mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-13 07:16:37 +08:00
some early steps remaking the GUI with UnityEngine.UI, working in all tested game so far
This commit is contained in:
@ -1,26 +1,26 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Explorer.UI;
|
||||
//using System;
|
||||
//using System.Collections;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using Explorer.UI;
|
||||
|
||||
namespace Explorer.CacheObject
|
||||
{
|
||||
public class CacheEnumerated : CacheObjectBase
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public IList RefIList { get; set; }
|
||||
public InteractiveEnumerable ParentEnumeration { get; set; }
|
||||
//namespace Explorer.CacheObject
|
||||
//{
|
||||
// public class CacheEnumerated : CacheObjectBase
|
||||
// {
|
||||
// public int Index { get; set; }
|
||||
// public IList RefIList { get; set; }
|
||||
// public InteractiveEnumerable ParentEnumeration { get; set; }
|
||||
|
||||
public override bool CanWrite => RefIList != null && ParentEnumeration.OwnerCacheObject.CanWrite;
|
||||
// public override bool CanWrite => RefIList != null && ParentEnumeration.OwnerCacheObject.CanWrite;
|
||||
|
||||
public override void SetValue()
|
||||
{
|
||||
RefIList[Index] = IValue.Value;
|
||||
ParentEnumeration.Value = RefIList;
|
||||
// public override void SetValue()
|
||||
// {
|
||||
// RefIList[Index] = IValue.Value;
|
||||
// ParentEnumeration.Value = RefIList;
|
||||
|
||||
ParentEnumeration.OwnerCacheObject.SetValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ParentEnumeration.OwnerCacheObject.SetValue();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -1,76 +1,76 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Explorer.CacheObject;
|
||||
using UnityEngine;
|
||||
using Explorer.Helpers;
|
||||
//using System;
|
||||
//using System.Reflection;
|
||||
//using Explorer.CacheObject;
|
||||
//using UnityEngine;
|
||||
//using Explorer.Helpers;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
public static class CacheFactory
|
||||
{
|
||||
public static CacheObjectBase GetCacheObject(object obj)
|
||||
{
|
||||
if (obj == null) return null;
|
||||
//namespace Explorer
|
||||
//{
|
||||
// public static class CacheFactory
|
||||
// {
|
||||
// public static CacheObjectBase GetCacheObject(object obj)
|
||||
// {
|
||||
// if (obj == null) return null;
|
||||
|
||||
return GetCacheObject(obj, ReflectionHelpers.GetActualType(obj));
|
||||
}
|
||||
// return GetCacheObject(obj, ReflectionHelpers.GetActualType(obj));
|
||||
// }
|
||||
|
||||
public static CacheObjectBase GetCacheObject(object obj, Type type)
|
||||
{
|
||||
var ret = new CacheObjectBase();
|
||||
ret.Init(obj, type);
|
||||
return ret;
|
||||
}
|
||||
// public static CacheObjectBase GetCacheObject(object obj, Type type)
|
||||
// {
|
||||
// var ret = new CacheObjectBase();
|
||||
// ret.Init(obj, type);
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
public static CacheMember GetCacheObject(MemberInfo member, object declaringInstance)
|
||||
{
|
||||
CacheMember ret;
|
||||
// public static CacheMember GetCacheObject(MemberInfo member, object declaringInstance)
|
||||
// {
|
||||
// CacheMember ret;
|
||||
|
||||
if (member is MethodInfo mi && CanProcessArgs(mi.GetParameters()))
|
||||
{
|
||||
ret = new CacheMethod();
|
||||
ret.InitMember(mi, declaringInstance);
|
||||
}
|
||||
else if (member is PropertyInfo pi && CanProcessArgs(pi.GetIndexParameters()))
|
||||
{
|
||||
ret = new CacheProperty();
|
||||
ret.InitMember(pi, declaringInstance);
|
||||
}
|
||||
else if (member is FieldInfo fi)
|
||||
{
|
||||
ret = new CacheField();
|
||||
ret.InitMember(fi, declaringInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// if (member is MethodInfo mi && CanProcessArgs(mi.GetParameters()))
|
||||
// {
|
||||
// ret = new CacheMethod();
|
||||
// ret.InitMember(mi, declaringInstance);
|
||||
// }
|
||||
// else if (member is PropertyInfo pi && CanProcessArgs(pi.GetIndexParameters()))
|
||||
// {
|
||||
// ret = new CacheProperty();
|
||||
// ret.InitMember(pi, declaringInstance);
|
||||
// }
|
||||
// else if (member is FieldInfo fi)
|
||||
// {
|
||||
// ret = new CacheField();
|
||||
// ret.InitMember(fi, declaringInstance);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
return ret;
|
||||
}
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
public static bool CanProcessArgs(ParameterInfo[] parameters)
|
||||
{
|
||||
foreach (var param in parameters)
|
||||
{
|
||||
var pType = param.ParameterType;
|
||||
// public static bool CanProcessArgs(ParameterInfo[] parameters)
|
||||
// {
|
||||
// foreach (var param in parameters)
|
||||
// {
|
||||
// var pType = param.ParameterType;
|
||||
|
||||
if (pType.IsByRef && pType.HasElementType)
|
||||
{
|
||||
pType = pType.GetElementType();
|
||||
}
|
||||
// if (pType.IsByRef && pType.HasElementType)
|
||||
// {
|
||||
// pType = pType.GetElementType();
|
||||
// }
|
||||
|
||||
if (pType.IsPrimitive || pType == typeof(string))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// if (pType.IsPrimitive || pType == typeof(string))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -1,54 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using Explorer.UI;
|
||||
using Explorer.Helpers;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Reflection;
|
||||
//using Explorer.UI;
|
||||
//using Explorer.Helpers;
|
||||
|
||||
namespace Explorer.CacheObject
|
||||
{
|
||||
public class CacheField : CacheMember
|
||||
{
|
||||
public override bool IsStatic => (MemInfo as FieldInfo).IsStatic;
|
||||
//namespace Explorer.CacheObject
|
||||
//{
|
||||
// public class CacheField : CacheMember
|
||||
// {
|
||||
// public override bool IsStatic => (MemInfo as FieldInfo).IsStatic;
|
||||
|
||||
public override void InitMember(MemberInfo member, object declaringInstance)
|
||||
{
|
||||
base.InitMember(member, declaringInstance);
|
||||
// public override void InitMember(MemberInfo member, object declaringInstance)
|
||||
// {
|
||||
// base.InitMember(member, declaringInstance);
|
||||
|
||||
base.Init(null, (member as FieldInfo).FieldType);
|
||||
// base.Init(null, (member as FieldInfo).FieldType);
|
||||
|
||||
UpdateValue();
|
||||
}
|
||||
// UpdateValue();
|
||||
// }
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
if (IValue is InteractiveDictionary iDict)
|
||||
{
|
||||
if (!iDict.EnsureDictionaryIsSupported())
|
||||
{
|
||||
ReflectionException = "Not supported due to TypeInitializationException";
|
||||
return;
|
||||
}
|
||||
}
|
||||
// public override void UpdateValue()
|
||||
// {
|
||||
// if (IValue is InteractiveDictionary iDict)
|
||||
// {
|
||||
// if (!iDict.EnsureDictionaryIsSupported())
|
||||
// {
|
||||
// ReflectionException = "Not supported due to TypeInitializationException";
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
try
|
||||
{
|
||||
var fi = MemInfo as FieldInfo;
|
||||
IValue.Value = fi.GetValue(fi.IsStatic ? null : DeclaringInstance);
|
||||
// try
|
||||
// {
|
||||
// var fi = MemInfo as FieldInfo;
|
||||
// IValue.Value = fi.GetValue(fi.IsStatic ? null : DeclaringInstance);
|
||||
|
||||
base.UpdateValue();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ReflectionException = ReflectionHelpers.ExceptionToString(e);
|
||||
}
|
||||
}
|
||||
// base.UpdateValue();
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// ReflectionException = ReflectionHelpers.ExceptionToString(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
public override void SetValue()
|
||||
{
|
||||
var fi = MemInfo as FieldInfo;
|
||||
fi.SetValue(fi.IsStatic ? null : DeclaringInstance, IValue.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
// public override void SetValue()
|
||||
// {
|
||||
// var fi = MemInfo as FieldInfo;
|
||||
// fi.SetValue(fi.IsStatic ? null : DeclaringInstance, IValue.Value);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -1,226 +1,226 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using Explorer.UI;
|
||||
using Explorer.UI.Shared;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Reflection;
|
||||
//using UnityEngine;
|
||||
//using Explorer.UI;
|
||||
//using Explorer.UI.Shared;
|
||||
|
||||
namespace Explorer.CacheObject
|
||||
{
|
||||
public class CacheMember : CacheObjectBase
|
||||
{
|
||||
public MemberInfo MemInfo { get; set; }
|
||||
public Type DeclaringType { get; set; }
|
||||
public object DeclaringInstance { get; set; }
|
||||
//namespace Explorer.CacheObject
|
||||
//{
|
||||
// public class CacheMember : CacheObjectBase
|
||||
// {
|
||||
// public MemberInfo MemInfo { get; set; }
|
||||
// public Type DeclaringType { get; set; }
|
||||
// public object DeclaringInstance { get; set; }
|
||||
|
||||
public virtual bool IsStatic { get; private set; }
|
||||
// public virtual bool IsStatic { get; private set; }
|
||||
|
||||
public override bool HasParameters => m_arguments != null && m_arguments.Length > 0;
|
||||
public override bool IsMember => true;
|
||||
// public override bool HasParameters => m_arguments != null && m_arguments.Length > 0;
|
||||
// public override bool IsMember => true;
|
||||
|
||||
public string RichTextName => m_richTextName ?? GetRichTextName();
|
||||
private string m_richTextName;
|
||||
// public string RichTextName => m_richTextName ?? GetRichTextName();
|
||||
// private string m_richTextName;
|
||||
|
||||
public override bool CanWrite => m_canWrite ?? GetCanWrite();
|
||||
private bool? m_canWrite;
|
||||
// public override bool CanWrite => m_canWrite ?? GetCanWrite();
|
||||
// private bool? m_canWrite;
|
||||
|
||||
public string ReflectionException { get; set; }
|
||||
// public string ReflectionException { get; set; }
|
||||
|
||||
public bool m_evaluated = false;
|
||||
public bool m_isEvaluating;
|
||||
public ParameterInfo[] m_arguments = new ParameterInfo[0];
|
||||
public string[] m_argumentInput = new string[0];
|
||||
// public bool m_evaluated = false;
|
||||
// public bool m_isEvaluating;
|
||||
// public ParameterInfo[] m_arguments = new ParameterInfo[0];
|
||||
// public string[] m_argumentInput = new string[0];
|
||||
|
||||
public virtual void InitMember(MemberInfo member, object declaringInstance)
|
||||
{
|
||||
MemInfo = member;
|
||||
DeclaringInstance = declaringInstance;
|
||||
DeclaringType = member.DeclaringType;
|
||||
}
|
||||
// public virtual void InitMember(MemberInfo member, object declaringInstance)
|
||||
// {
|
||||
// MemInfo = member;
|
||||
// DeclaringInstance = declaringInstance;
|
||||
// DeclaringType = member.DeclaringType;
|
||||
// }
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
base.UpdateValue();
|
||||
}
|
||||
// public override void UpdateValue()
|
||||
// {
|
||||
// base.UpdateValue();
|
||||
// }
|
||||
|
||||
public override void SetValue()
|
||||
{
|
||||
// ...
|
||||
}
|
||||
// public override void SetValue()
|
||||
// {
|
||||
// // ...
|
||||
// }
|
||||
|
||||
public object[] ParseArguments()
|
||||
{
|
||||
if (m_arguments.Length < 1)
|
||||
{
|
||||
return new object[0];
|
||||
}
|
||||
// public object[] ParseArguments()
|
||||
// {
|
||||
// if (m_arguments.Length < 1)
|
||||
// {
|
||||
// return new object[0];
|
||||
// }
|
||||
|
||||
var parsedArgs = new List<object>();
|
||||
for (int i = 0; i < m_arguments.Length; i++)
|
||||
{
|
||||
var input = m_argumentInput[i];
|
||||
var type = m_arguments[i].ParameterType;
|
||||
// var parsedArgs = new List<object>();
|
||||
// for (int i = 0; i < m_arguments.Length; i++)
|
||||
// {
|
||||
// var input = m_argumentInput[i];
|
||||
// var type = m_arguments[i].ParameterType;
|
||||
|
||||
if (type.IsByRef)
|
||||
{
|
||||
type = type.GetElementType();
|
||||
}
|
||||
// if (type.IsByRef)
|
||||
// {
|
||||
// type = type.GetElementType();
|
||||
// }
|
||||
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
{
|
||||
if (type == typeof(string))
|
||||
{
|
||||
parsedArgs.Add(input);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
var arg = type.GetMethod("Parse", new Type[] { typeof(string) })
|
||||
.Invoke(null, new object[] { input });
|
||||
// if (!string.IsNullOrEmpty(input))
|
||||
// {
|
||||
// if (type == typeof(string))
|
||||
// {
|
||||
// parsedArgs.Add(input);
|
||||
// continue;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var arg = type.GetMethod("Parse", new Type[] { typeof(string) })
|
||||
// .Invoke(null, new object[] { input });
|
||||
|
||||
parsedArgs.Add(arg);
|
||||
continue;
|
||||
}
|
||||
catch
|
||||
{
|
||||
ExplorerCore.Log($"Argument #{i} '{m_arguments[i].Name}' ({type.Name}), could not parse input '{input}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
// parsedArgs.Add(arg);
|
||||
// continue;
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// ExplorerCore.Log($"Argument #{i} '{m_arguments[i].Name}' ({type.Name}), could not parse input '{input}'.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// No input, see if there is a default value.
|
||||
if (HasDefaultValue(m_arguments[i]))
|
||||
{
|
||||
parsedArgs.Add(m_arguments[i].DefaultValue);
|
||||
continue;
|
||||
}
|
||||
// // No input, see if there is a default value.
|
||||
// if (HasDefaultValue(m_arguments[i]))
|
||||
// {
|
||||
// parsedArgs.Add(m_arguments[i].DefaultValue);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// Try add a null arg I guess
|
||||
parsedArgs.Add(null);
|
||||
}
|
||||
// // Try add a null arg I guess
|
||||
// parsedArgs.Add(null);
|
||||
// }
|
||||
|
||||
return parsedArgs.ToArray();
|
||||
}
|
||||
// return parsedArgs.ToArray();
|
||||
// }
|
||||
|
||||
public static bool HasDefaultValue(ParameterInfo arg) => arg.DefaultValue != DBNull.Value;
|
||||
// public static bool HasDefaultValue(ParameterInfo arg) => arg.DefaultValue != DBNull.Value;
|
||||
|
||||
public void DrawArgsInput()
|
||||
{
|
||||
GUILayout.Label($"<b><color=orange>Arguments:</color></b>", new GUILayoutOption[0]);
|
||||
for (int i = 0; i < this.m_arguments.Length; i++)
|
||||
{
|
||||
var name = this.m_arguments[i].Name;
|
||||
var input = this.m_argumentInput[i];
|
||||
var type = this.m_arguments[i].ParameterType.Name;
|
||||
// public void DrawArgsInput()
|
||||
// {
|
||||
// GUILayout.Label($"<b><color=orange>Arguments:</color></b>", new GUILayoutOption[0]);
|
||||
// for (int i = 0; i < this.m_arguments.Length; i++)
|
||||
// {
|
||||
// var name = this.m_arguments[i].Name;
|
||||
// var input = this.m_argumentInput[i];
|
||||
// var type = this.m_arguments[i].ParameterType.Name;
|
||||
|
||||
var label = $"<color={Syntax.Class_Instance}>{type}</color> ";
|
||||
label += $"<color={Syntax.Local}>{name}</color>";
|
||||
if (HasDefaultValue(this.m_arguments[i]))
|
||||
{
|
||||
label = $"<i>[{label} = {this.m_arguments[i].DefaultValue ?? "null"}]</i>";
|
||||
}
|
||||
// var label = $"<color={Syntax.Class_Instance}>{type}</color> ";
|
||||
// label += $"<color={Syntax.Local}>{name}</color>";
|
||||
// if (HasDefaultValue(this.m_arguments[i]))
|
||||
// {
|
||||
// label = $"<i>[{label} = {this.m_arguments[i].DefaultValue ?? "null"}]</i>";
|
||||
// }
|
||||
|
||||
GUIHelper.BeginHorizontal(new GUILayoutOption[0]);
|
||||
// GUIHelper.BeginHorizontal(new GUILayoutOption[0]);
|
||||
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||
// GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
GUILayout.Label(i.ToString(), new GUILayoutOption[] { GUILayout.Width(15) });
|
||||
GUILayout.Label(label, new GUILayoutOption[] { GUIHelper.ExpandWidth(false) });
|
||||
this.m_argumentInput[i] = GUIHelper.TextField(input, new GUILayoutOption[] { GUIHelper.ExpandWidth(true) });
|
||||
// GUILayout.Label(i.ToString(), new GUILayoutOption[] { GUILayout.Width(15) });
|
||||
// GUILayout.Label(label, new GUILayoutOption[] { GUILayout.ExpandWidth(false) });
|
||||
// this.m_argumentInput[i] = GUIHelper.TextField(input, new GUILayoutOption[] { GUILayout.ExpandWidth(true) });
|
||||
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleLeft;
|
||||
// GUI.skin.label.alignment = TextAnchor.MiddleLeft;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
// GUILayout.EndHorizontal();
|
||||
// }
|
||||
// }
|
||||
|
||||
private bool GetCanWrite()
|
||||
{
|
||||
if (MemInfo is FieldInfo fi)
|
||||
m_canWrite = !(fi.IsLiteral && !fi.IsInitOnly);
|
||||
else if (MemInfo is PropertyInfo pi)
|
||||
m_canWrite = pi.CanWrite;
|
||||
else
|
||||
m_canWrite = false;
|
||||
// private bool GetCanWrite()
|
||||
// {
|
||||
// if (MemInfo is FieldInfo fi)
|
||||
// m_canWrite = !(fi.IsLiteral && !fi.IsInitOnly);
|
||||
// else if (MemInfo is PropertyInfo pi)
|
||||
// m_canWrite = pi.CanWrite;
|
||||
// else
|
||||
// m_canWrite = false;
|
||||
|
||||
return (bool)m_canWrite;
|
||||
}
|
||||
// return (bool)m_canWrite;
|
||||
// }
|
||||
|
||||
private string GetRichTextName()
|
||||
{
|
||||
string memberColor = "";
|
||||
bool isStatic = false;
|
||||
// private string GetRichTextName()
|
||||
// {
|
||||
// string memberColor = "";
|
||||
// bool isStatic = false;
|
||||
|
||||
if (MemInfo is FieldInfo fi)
|
||||
{
|
||||
if (fi.IsStatic)
|
||||
{
|
||||
isStatic = true;
|
||||
memberColor = Syntax.Field_Static;
|
||||
}
|
||||
else
|
||||
memberColor = Syntax.Field_Instance;
|
||||
}
|
||||
else if (MemInfo is MethodInfo mi)
|
||||
{
|
||||
if (mi.IsStatic)
|
||||
{
|
||||
isStatic = true;
|
||||
memberColor = Syntax.Method_Static;
|
||||
}
|
||||
else
|
||||
memberColor = Syntax.Method_Instance;
|
||||
}
|
||||
else if (MemInfo is PropertyInfo pi)
|
||||
{
|
||||
if (pi.GetAccessors()[0].IsStatic)
|
||||
{
|
||||
isStatic = true;
|
||||
memberColor = Syntax.Prop_Static;
|
||||
}
|
||||
else
|
||||
memberColor = Syntax.Prop_Instance;
|
||||
}
|
||||
// if (MemInfo is FieldInfo fi)
|
||||
// {
|
||||
// if (fi.IsStatic)
|
||||
// {
|
||||
// isStatic = true;
|
||||
// memberColor = Syntax.Field_Static;
|
||||
// }
|
||||
// else
|
||||
// memberColor = Syntax.Field_Instance;
|
||||
// }
|
||||
// else if (MemInfo is MethodInfo mi)
|
||||
// {
|
||||
// if (mi.IsStatic)
|
||||
// {
|
||||
// isStatic = true;
|
||||
// memberColor = Syntax.Method_Static;
|
||||
// }
|
||||
// else
|
||||
// memberColor = Syntax.Method_Instance;
|
||||
// }
|
||||
// else if (MemInfo is PropertyInfo pi)
|
||||
// {
|
||||
// if (pi.GetAccessors()[0].IsStatic)
|
||||
// {
|
||||
// isStatic = true;
|
||||
// memberColor = Syntax.Prop_Static;
|
||||
// }
|
||||
// else
|
||||
// memberColor = Syntax.Prop_Instance;
|
||||
// }
|
||||
|
||||
string classColor;
|
||||
if (MemInfo.DeclaringType.IsValueType)
|
||||
{
|
||||
classColor = Syntax.StructGreen;
|
||||
}
|
||||
else if (MemInfo.DeclaringType.IsAbstract && MemInfo.DeclaringType.IsSealed)
|
||||
{
|
||||
classColor = Syntax.Class_Static;
|
||||
}
|
||||
else
|
||||
{
|
||||
classColor = Syntax.Class_Instance;
|
||||
}
|
||||
// string classColor;
|
||||
// if (MemInfo.DeclaringType.IsValueType)
|
||||
// {
|
||||
// classColor = Syntax.StructGreen;
|
||||
// }
|
||||
// else if (MemInfo.DeclaringType.IsAbstract && MemInfo.DeclaringType.IsSealed)
|
||||
// {
|
||||
// classColor = Syntax.Class_Static;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// classColor = Syntax.Class_Instance;
|
||||
// }
|
||||
|
||||
m_richTextName = $"<color={classColor}>{MemInfo.DeclaringType.Name}</color>.";
|
||||
if (isStatic) m_richTextName += "<i>";
|
||||
m_richTextName += $"<color={memberColor}>{MemInfo.Name}</color>";
|
||||
if (isStatic) m_richTextName += "</i>";
|
||||
// m_richTextName = $"<color={classColor}>{MemInfo.DeclaringType.Name}</color>.";
|
||||
// if (isStatic) m_richTextName += "<i>";
|
||||
// m_richTextName += $"<color={memberColor}>{MemInfo.Name}</color>";
|
||||
// if (isStatic) m_richTextName += "</i>";
|
||||
|
||||
// generic method args
|
||||
if (this is CacheMethod cm && cm.GenericArgs.Length > 0)
|
||||
{
|
||||
m_richTextName += "<";
|
||||
// // generic method args
|
||||
// if (this is CacheMethod cm && cm.GenericArgs.Length > 0)
|
||||
// {
|
||||
// m_richTextName += "<";
|
||||
|
||||
var args = "";
|
||||
for (int i = 0; i < cm.GenericArgs.Length; i++)
|
||||
{
|
||||
if (args != "") args += ", ";
|
||||
args += $"<color={Syntax.StructGreen}>{cm.GenericArgs[i].Name}</color>";
|
||||
}
|
||||
m_richTextName += args;
|
||||
// var args = "";
|
||||
// for (int i = 0; i < cm.GenericArgs.Length; i++)
|
||||
// {
|
||||
// if (args != "") args += ", ";
|
||||
// args += $"<color={Syntax.StructGreen}>{cm.GenericArgs[i].Name}</color>";
|
||||
// }
|
||||
// m_richTextName += args;
|
||||
|
||||
m_richTextName += ">";
|
||||
}
|
||||
// m_richTextName += ">";
|
||||
// }
|
||||
|
||||
return m_richTextName;
|
||||
}
|
||||
}
|
||||
}
|
||||
// return m_richTextName;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -1,200 +1,200 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using Explorer.UI.Shared;
|
||||
using Explorer.Helpers;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Reflection;
|
||||
//using UnityEngine;
|
||||
//using Explorer.UI.Shared;
|
||||
//using Explorer.Helpers;
|
||||
|
||||
namespace Explorer.CacheObject
|
||||
{
|
||||
public class CacheMethod : CacheMember
|
||||
{
|
||||
private CacheObjectBase m_cachedReturnValue;
|
||||
//namespace Explorer.CacheObject
|
||||
//{
|
||||
// public class CacheMethod : CacheMember
|
||||
// {
|
||||
// private CacheObjectBase m_cachedReturnValue;
|
||||
|
||||
public override bool HasParameters => base.HasParameters || GenericArgs.Length > 0;
|
||||
// public override bool HasParameters => base.HasParameters || GenericArgs.Length > 0;
|
||||
|
||||
public override bool IsStatic => (MemInfo as MethodInfo).IsStatic;
|
||||
// public override bool IsStatic => (MemInfo as MethodInfo).IsStatic;
|
||||
|
||||
public Type[] GenericArgs { get; private set; }
|
||||
public Type[][] GenericConstraints { get; private set; }
|
||||
// public Type[] GenericArgs { get; private set; }
|
||||
// public Type[][] GenericConstraints { get; private set; }
|
||||
|
||||
public string[] GenericArgInput = new string[0];
|
||||
// public string[] GenericArgInput = new string[0];
|
||||
|
||||
public override void InitMember(MemberInfo member, object declaringInstance)
|
||||
{
|
||||
base.InitMember(member, declaringInstance);
|
||||
// public override void InitMember(MemberInfo member, object declaringInstance)
|
||||
// {
|
||||
// base.InitMember(member, declaringInstance);
|
||||
|
||||
var mi = MemInfo as MethodInfo;
|
||||
GenericArgs = mi.GetGenericArguments();
|
||||
// var mi = MemInfo as MethodInfo;
|
||||
// GenericArgs = mi.GetGenericArguments();
|
||||
|
||||
GenericConstraints = GenericArgs.Select(x => x.GetGenericParameterConstraints())
|
||||
.ToArray();
|
||||
// GenericConstraints = GenericArgs.Select(x => x.GetGenericParameterConstraints())
|
||||
// .ToArray();
|
||||
|
||||
GenericArgInput = new string[GenericArgs.Length];
|
||||
// GenericArgInput = new string[GenericArgs.Length];
|
||||
|
||||
m_arguments = mi.GetParameters();
|
||||
m_argumentInput = new string[m_arguments.Length];
|
||||
// m_arguments = mi.GetParameters();
|
||||
// m_argumentInput = new string[m_arguments.Length];
|
||||
|
||||
base.Init(null, mi.ReturnType);
|
||||
}
|
||||
// base.Init(null, mi.ReturnType);
|
||||
// }
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
// CacheMethod cannot UpdateValue directly. Need to Evaluate.
|
||||
}
|
||||
// public override void UpdateValue()
|
||||
// {
|
||||
// // CacheMethod cannot UpdateValue directly. Need to Evaluate.
|
||||
// }
|
||||
|
||||
public void Evaluate()
|
||||
{
|
||||
MethodInfo mi;
|
||||
if (GenericArgs.Length > 0)
|
||||
{
|
||||
mi = MakeGenericMethodFromInput();
|
||||
if (mi == null) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
mi = MemInfo as MethodInfo;
|
||||
}
|
||||
// public void Evaluate()
|
||||
// {
|
||||
// MethodInfo mi;
|
||||
// if (GenericArgs.Length > 0)
|
||||
// {
|
||||
// mi = MakeGenericMethodFromInput();
|
||||
// if (mi == null) return;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// mi = MemInfo as MethodInfo;
|
||||
// }
|
||||
|
||||
object ret = null;
|
||||
// object ret = null;
|
||||
|
||||
try
|
||||
{
|
||||
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, ParseArguments());
|
||||
m_evaluated = true;
|
||||
m_isEvaluating = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.LogWarning($"Exception evaluating: {e.GetType()}, {e.Message}");
|
||||
ReflectionException = ReflectionHelpers.ExceptionToString(e);
|
||||
}
|
||||
// try
|
||||
// {
|
||||
// ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, ParseArguments());
|
||||
// m_evaluated = true;
|
||||
// m_isEvaluating = false;
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// ExplorerCore.LogWarning($"Exception evaluating: {e.GetType()}, {e.Message}");
|
||||
// ReflectionException = ReflectionHelpers.ExceptionToString(e);
|
||||
// }
|
||||
|
||||
if (ret != null)
|
||||
{
|
||||
//m_cachedReturnValue = CacheFactory.GetTypeAndCacheObject(ret);
|
||||
m_cachedReturnValue = CacheFactory.GetCacheObject(ret);
|
||||
m_cachedReturnValue.UpdateValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_cachedReturnValue = null;
|
||||
}
|
||||
}
|
||||
// if (ret != null)
|
||||
// {
|
||||
// //m_cachedReturnValue = CacheFactory.GetTypeAndCacheObject(ret);
|
||||
// m_cachedReturnValue = CacheFactory.GetCacheObject(ret);
|
||||
// m_cachedReturnValue.UpdateValue();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// m_cachedReturnValue = null;
|
||||
// }
|
||||
// }
|
||||
|
||||
private MethodInfo MakeGenericMethodFromInput()
|
||||
{
|
||||
var mi = MemInfo as MethodInfo;
|
||||
// private MethodInfo MakeGenericMethodFromInput()
|
||||
// {
|
||||
// var mi = MemInfo as MethodInfo;
|
||||
|
||||
var list = new List<Type>();
|
||||
for (int i = 0; i < GenericArgs.Length; i++)
|
||||
{
|
||||
var input = GenericArgInput[i];
|
||||
if (ReflectionHelpers.GetTypeByName(input) is Type t)
|
||||
{
|
||||
if (GenericConstraints[i].Length == 0)
|
||||
{
|
||||
list.Add(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var constraint in GenericConstraints[i].Where(x => x != null))
|
||||
{
|
||||
if (!constraint.IsAssignableFrom(t))
|
||||
{
|
||||
ExplorerCore.LogWarning($"Generic argument #{i}, '{input}' is not assignable from the constraint '{constraint}'!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// var list = new List<Type>();
|
||||
// for (int i = 0; i < GenericArgs.Length; i++)
|
||||
// {
|
||||
// var input = GenericArgInput[i];
|
||||
// if (ReflectionHelpers.GetTypeByName(input) is Type t)
|
||||
// {
|
||||
// if (GenericConstraints[i].Length == 0)
|
||||
// {
|
||||
// list.Add(t);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// foreach (var constraint in GenericConstraints[i].Where(x => x != null))
|
||||
// {
|
||||
// if (!constraint.IsAssignableFrom(t))
|
||||
// {
|
||||
// ExplorerCore.LogWarning($"Generic argument #{i}, '{input}' is not assignable from the constraint '{constraint}'!");
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
list.Add(t);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExplorerCore.LogWarning($"Generic argument #{i}, could not get any type by the name of '{input}'!" +
|
||||
$" Make sure you use the full name, including the NameSpace.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// list.Add(t);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ExplorerCore.LogWarning($"Generic argument #{i}, could not get any type by the name of '{input}'!" +
|
||||
// $" Make sure you use the full name, including the NameSpace.");
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
// make into a generic with type list
|
||||
mi = mi.MakeGenericMethod(list.ToArray());
|
||||
// // make into a generic with type list
|
||||
// mi = mi.MakeGenericMethod(list.ToArray());
|
||||
|
||||
return mi;
|
||||
}
|
||||
// return mi;
|
||||
// }
|
||||
|
||||
// ==== GUI DRAW ====
|
||||
// // ==== GUI DRAW ====
|
||||
|
||||
//public override void Draw(Rect window, float width)
|
||||
//{
|
||||
// base.Draw(window, width);
|
||||
//}
|
||||
// //public override void Draw(Rect window, float width)
|
||||
// //{
|
||||
// // base.Draw(window, width);
|
||||
// //}
|
||||
|
||||
public void DrawValue(Rect window, float width)
|
||||
{
|
||||
string typeLabel = $"<color={Syntax.Class_Instance}>{IValue.ValueType.FullName}</color>";
|
||||
// public void DrawValue(Rect window, float width)
|
||||
// {
|
||||
// string typeLabel = $"<color={Syntax.Class_Instance}>{IValue.ValueType.FullName}</color>";
|
||||
|
||||
if (m_evaluated)
|
||||
{
|
||||
if (m_cachedReturnValue != null)
|
||||
{
|
||||
m_cachedReturnValue.IValue.DrawValue(window, width);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Label($"null ({typeLabel})", new GUILayoutOption[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> ({typeLabel})", new GUILayoutOption[0]);
|
||||
}
|
||||
}
|
||||
// if (m_evaluated)
|
||||
// {
|
||||
// if (m_cachedReturnValue != null)
|
||||
// {
|
||||
// m_cachedReturnValue.IValue.DrawValue(window, width);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// GUILayout.Label($"null ({typeLabel})", new GUILayoutOption[0]);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> ({typeLabel})", new GUILayoutOption[0]);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void DrawGenericArgsInput()
|
||||
{
|
||||
GUILayout.Label($"<b><color=orange>Generic Arguments:</color></b>", new GUILayoutOption[0]);
|
||||
// public void DrawGenericArgsInput()
|
||||
// {
|
||||
// GUILayout.Label($"<b><color=orange>Generic Arguments:</color></b>", new GUILayoutOption[0]);
|
||||
|
||||
for (int i = 0; i < this.GenericArgs.Length; i++)
|
||||
{
|
||||
string types = "";
|
||||
if (this.GenericConstraints[i].Length > 0)
|
||||
{
|
||||
foreach (var constraint in this.GenericConstraints[i])
|
||||
{
|
||||
if (types != "") types += ", ";
|
||||
// for (int i = 0; i < this.GenericArgs.Length; i++)
|
||||
// {
|
||||
// string types = "";
|
||||
// if (this.GenericConstraints[i].Length > 0)
|
||||
// {
|
||||
// foreach (var constraint in this.GenericConstraints[i])
|
||||
// {
|
||||
// if (types != "") types += ", ";
|
||||
|
||||
string type;
|
||||
// string type;
|
||||
|
||||
if (constraint == null)
|
||||
type = "Any";
|
||||
else
|
||||
type = constraint.ToString();
|
||||
// if (constraint == null)
|
||||
// type = "Any";
|
||||
// else
|
||||
// type = constraint.ToString();
|
||||
|
||||
types += $"<color={Syntax.Class_Instance}>{type}</color>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
types = $"<color={Syntax.Class_Instance}>Any</color>";
|
||||
}
|
||||
var input = this.GenericArgInput[i];
|
||||
// types += $"<color={Syntax.Class_Instance}>{type}</color>";
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// types = $"<color={Syntax.Class_Instance}>Any</color>";
|
||||
// }
|
||||
// var input = this.GenericArgInput[i];
|
||||
|
||||
GUIHelper.BeginHorizontal(new GUILayoutOption[0]);
|
||||
// GUIHelper.BeginHorizontal(new GUILayoutOption[0]);
|
||||
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||
GUILayout.Label(
|
||||
$"<color={Syntax.StructGreen}>{this.GenericArgs[i].Name}</color>",
|
||||
new GUILayoutOption[] { GUILayout.Width(15) }
|
||||
);
|
||||
this.GenericArgInput[i] = GUIHelper.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) });
|
||||
GUI.skin.label.alignment = TextAnchor.MiddleLeft;
|
||||
GUILayout.Label(types, new GUILayoutOption[0]);
|
||||
// GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||
// GUILayout.Label(
|
||||
// $"<color={Syntax.StructGreen}>{this.GenericArgs[i].Name}</color>",
|
||||
// new GUILayoutOption[] { GUILayout.Width(15) }
|
||||
// );
|
||||
// this.GenericArgInput[i] = GUIHelper.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) });
|
||||
// GUI.skin.label.alignment = TextAnchor.MiddleLeft;
|
||||
// GUILayout.Label(types, new GUILayoutOption[0]);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// GUILayout.EndHorizontal();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -1,117 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using Explorer.UI;
|
||||
using Explorer.UI.Shared;
|
||||
using Explorer.Helpers;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Reflection;
|
||||
//using UnityEngine;
|
||||
//using Explorer.UI;
|
||||
//using Explorer.UI.Shared;
|
||||
//using Explorer.Helpers;
|
||||
|
||||
namespace Explorer.CacheObject
|
||||
{
|
||||
public class CacheObjectBase
|
||||
{
|
||||
public InteractiveValue IValue;
|
||||
//namespace Explorer.CacheObject
|
||||
//{
|
||||
// public class CacheObjectBase
|
||||
// {
|
||||
// public InteractiveValue IValue;
|
||||
|
||||
public virtual bool CanWrite => false;
|
||||
public virtual bool HasParameters => false;
|
||||
public virtual bool IsMember => false;
|
||||
// public virtual bool CanWrite => false;
|
||||
// public virtual bool HasParameters => false;
|
||||
// public virtual bool IsMember => false;
|
||||
|
||||
public bool IsStaticClassSearchResult { get; set; }
|
||||
// public bool IsStaticClassSearchResult { get; set; }
|
||||
|
||||
public virtual void Init(object obj, Type valueType)
|
||||
{
|
||||
if (valueType == null && obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// public virtual void Init(object obj, Type valueType)
|
||||
// {
|
||||
// if (valueType == null && obj == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
//ExplorerCore.Log("Initializing InteractiveValue of type " + valueType.FullName);
|
||||
// //ExplorerCore.Log("Initializing InteractiveValue of type " + valueType.FullName);
|
||||
|
||||
InteractiveValue interactive;
|
||||
// InteractiveValue interactive;
|
||||
|
||||
if (valueType == typeof(GameObject) || valueType == typeof(Transform))
|
||||
{
|
||||
interactive = new InteractiveGameObject();
|
||||
}
|
||||
else if (valueType == typeof(Texture2D))
|
||||
{
|
||||
interactive = new InteractiveTexture2D();
|
||||
}
|
||||
else if (valueType == typeof(Texture))
|
||||
{
|
||||
interactive = new InteractiveTexture();
|
||||
}
|
||||
else if (valueType == typeof(Sprite))
|
||||
{
|
||||
interactive = new InteractiveSprite();
|
||||
}
|
||||
else if (valueType.IsPrimitive || valueType == typeof(string))
|
||||
{
|
||||
interactive = new InteractivePrimitive();
|
||||
}
|
||||
else if (valueType.IsEnum)
|
||||
{
|
||||
if (valueType.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] attributes && attributes.Length > 0)
|
||||
{
|
||||
interactive = new InteractiveFlags();
|
||||
}
|
||||
else
|
||||
{
|
||||
interactive = new InteractiveEnum();
|
||||
}
|
||||
}
|
||||
else if (valueType == typeof(Vector2) || valueType == typeof(Vector3) || valueType == typeof(Vector4))
|
||||
{
|
||||
interactive = new InteractiveVector();
|
||||
}
|
||||
else if (valueType == typeof(Quaternion))
|
||||
{
|
||||
interactive = new InteractiveQuaternion();
|
||||
}
|
||||
else if (valueType == typeof(Color))
|
||||
{
|
||||
interactive = new InteractiveColor();
|
||||
}
|
||||
else if (valueType == typeof(Rect))
|
||||
{
|
||||
interactive = new InteractiveRect();
|
||||
}
|
||||
// must check this before IsEnumerable
|
||||
else if (ReflectionHelpers.IsDictionary(valueType))
|
||||
{
|
||||
interactive = new InteractiveDictionary();
|
||||
}
|
||||
else if (ReflectionHelpers.IsEnumerable(valueType))
|
||||
{
|
||||
interactive = new InteractiveEnumerable();
|
||||
}
|
||||
else
|
||||
{
|
||||
interactive = new InteractiveValue();
|
||||
}
|
||||
// if (valueType == typeof(GameObject) || valueType == typeof(Transform))
|
||||
// {
|
||||
// interactive = new InteractiveGameObject();
|
||||
// }
|
||||
// else if (valueType == typeof(Texture2D))
|
||||
// {
|
||||
// interactive = new InteractiveTexture2D();
|
||||
// }
|
||||
// else if (valueType == typeof(Texture))
|
||||
// {
|
||||
// interactive = new InteractiveTexture();
|
||||
// }
|
||||
// else if (valueType == typeof(Sprite))
|
||||
// {
|
||||
// interactive = new InteractiveSprite();
|
||||
// }
|
||||
// else if (valueType.IsPrimitive || valueType == typeof(string))
|
||||
// {
|
||||
// interactive = new InteractivePrimitive();
|
||||
// }
|
||||
// else if (valueType.IsEnum)
|
||||
// {
|
||||
// if (valueType.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] attributes && attributes.Length > 0)
|
||||
// {
|
||||
// interactive = new InteractiveFlags();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// interactive = new InteractiveEnum();
|
||||
// }
|
||||
// }
|
||||
// else if (valueType == typeof(Vector2) || valueType == typeof(Vector3) || valueType == typeof(Vector4))
|
||||
// {
|
||||
// interactive = new InteractiveVector();
|
||||
// }
|
||||
// else if (valueType == typeof(Quaternion))
|
||||
// {
|
||||
// interactive = new InteractiveQuaternion();
|
||||
// }
|
||||
// else if (valueType == typeof(Color))
|
||||
// {
|
||||
// interactive = new InteractiveColor();
|
||||
// }
|
||||
// else if (valueType == typeof(Rect))
|
||||
// {
|
||||
// interactive = new InteractiveRect();
|
||||
// }
|
||||
// // must check this before IsEnumerable
|
||||
// else if (ReflectionHelpers.IsDictionary(valueType))
|
||||
// {
|
||||
// interactive = new InteractiveDictionary();
|
||||
// }
|
||||
// else if (ReflectionHelpers.IsEnumerable(valueType))
|
||||
// {
|
||||
// interactive = new InteractiveEnumerable();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// interactive = new InteractiveValue();
|
||||
// }
|
||||
|
||||
interactive.Value = obj;
|
||||
interactive.ValueType = valueType;
|
||||
// interactive.Value = obj;
|
||||
// interactive.ValueType = valueType;
|
||||
|
||||
this.IValue = interactive;
|
||||
this.IValue.OwnerCacheObject = this;
|
||||
// this.IValue = interactive;
|
||||
// this.IValue.OwnerCacheObject = this;
|
||||
|
||||
UpdateValue();
|
||||
// UpdateValue();
|
||||
|
||||
this.IValue.Init();
|
||||
}
|
||||
// this.IValue.Init();
|
||||
// }
|
||||
|
||||
public virtual void Draw(Rect window, float width)
|
||||
{
|
||||
IValue.Draw(window, width);
|
||||
}
|
||||
// public virtual void Draw(Rect window, float width)
|
||||
// {
|
||||
// IValue.Draw(window, width);
|
||||
// }
|
||||
|
||||
public virtual void UpdateValue()
|
||||
{
|
||||
IValue.UpdateValue();
|
||||
}
|
||||
// public virtual void UpdateValue()
|
||||
// {
|
||||
// IValue.UpdateValue();
|
||||
// }
|
||||
|
||||
public virtual void SetValue() => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
// public virtual void SetValue() => throw new NotImplementedException();
|
||||
// }
|
||||
//}
|
||||
|
@ -1,84 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using Explorer.UI;
|
||||
using Explorer.Helpers;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Reflection;
|
||||
//using Explorer.UI;
|
||||
//using Explorer.Helpers;
|
||||
|
||||
namespace Explorer.CacheObject
|
||||
{
|
||||
public class CacheProperty : CacheMember
|
||||
{
|
||||
public override bool IsStatic => (MemInfo as PropertyInfo).GetAccessors()[0].IsStatic;
|
||||
//namespace Explorer.CacheObject
|
||||
//{
|
||||
// public class CacheProperty : CacheMember
|
||||
// {
|
||||
// public override bool IsStatic => (MemInfo as PropertyInfo).GetAccessors()[0].IsStatic;
|
||||
|
||||
public override void InitMember(MemberInfo member, object declaringInstance)
|
||||
{
|
||||
base.InitMember(member, declaringInstance);
|
||||
// public override void InitMember(MemberInfo member, object declaringInstance)
|
||||
// {
|
||||
// base.InitMember(member, declaringInstance);
|
||||
|
||||
var pi = member as PropertyInfo;
|
||||
// var pi = member as PropertyInfo;
|
||||
|
||||
this.m_arguments = pi.GetIndexParameters();
|
||||
this.m_argumentInput = new string[m_arguments.Length];
|
||||
// this.m_arguments = pi.GetIndexParameters();
|
||||
// this.m_argumentInput = new string[m_arguments.Length];
|
||||
|
||||
base.Init(null, pi.PropertyType);
|
||||
// base.Init(null, pi.PropertyType);
|
||||
|
||||
UpdateValue();
|
||||
}
|
||||
// UpdateValue();
|
||||
// }
|
||||
|
||||
public override void UpdateValue()
|
||||
{
|
||||
if (HasParameters && !m_isEvaluating)
|
||||
{
|
||||
// Need to enter parameters first.
|
||||
return;
|
||||
}
|
||||
// public override void UpdateValue()
|
||||
// {
|
||||
// if (HasParameters && !m_isEvaluating)
|
||||
// {
|
||||
// // Need to enter parameters first.
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (IValue is InteractiveDictionary iDict)
|
||||
{
|
||||
if (!iDict.EnsureDictionaryIsSupported())
|
||||
{
|
||||
ReflectionException = "Not supported due to TypeInitializationException";
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if (IValue is InteractiveDictionary iDict)
|
||||
// {
|
||||
// if (!iDict.EnsureDictionaryIsSupported())
|
||||
// {
|
||||
// ReflectionException = "Not supported due to TypeInitializationException";
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
try
|
||||
{
|
||||
var pi = MemInfo as PropertyInfo;
|
||||
// try
|
||||
// {
|
||||
// var pi = MemInfo as PropertyInfo;
|
||||
|
||||
if (pi.CanRead)
|
||||
{
|
||||
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
|
||||
// if (pi.CanRead)
|
||||
// {
|
||||
// var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
|
||||
|
||||
IValue.Value = pi.GetValue(target, ParseArguments());
|
||||
// IValue.Value = pi.GetValue(target, ParseArguments());
|
||||
|
||||
base.UpdateValue();
|
||||
}
|
||||
else // create a dummy value for Write-Only properties.
|
||||
{
|
||||
if (IValue.ValueType == typeof(string))
|
||||
{
|
||||
IValue.Value = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
IValue.Value = Activator.CreateInstance(IValue.ValueType);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ReflectionException = ReflectionHelpers.ExceptionToString(e);
|
||||
}
|
||||
}
|
||||
// base.UpdateValue();
|
||||
// }
|
||||
// else // create a dummy value for Write-Only properties.
|
||||
// {
|
||||
// if (IValue.ValueType == typeof(string))
|
||||
// {
|
||||
// IValue.Value = "";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// IValue.Value = Activator.CreateInstance(IValue.ValueType);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// ReflectionException = ReflectionHelpers.ExceptionToString(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
public override void SetValue()
|
||||
{
|
||||
var pi = MemInfo as PropertyInfo;
|
||||
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
|
||||
// public override void SetValue()
|
||||
// {
|
||||
// var pi = MemInfo as PropertyInfo;
|
||||
// var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
|
||||
|
||||
pi.SetValue(target, IValue.Value, ParseArguments());
|
||||
}
|
||||
}
|
||||
}
|
||||
// pi.SetValue(target, IValue.Value, ParseArguments());
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
Reference in New Issue
Block a user