mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +08:00
Improved interaction with generic methods and some minor UI fixes
This commit is contained in:
parent
643bb4519c
commit
129a7e3765
@ -305,15 +305,8 @@ namespace Explorer
|
|||||||
var pi = MemInfo as PropertyInfo;
|
var pi = MemInfo as PropertyInfo;
|
||||||
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
|
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
|
||||||
|
|
||||||
if (HasParameters)
|
|
||||||
{
|
|
||||||
Value = pi.GetValue(target, ParseArguments());
|
Value = pi.GetValue(target, ParseArguments());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Value = pi.GetValue(target, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ReflectionException = null;
|
ReflectionException = null;
|
||||||
m_evaluated = true;
|
m_evaluated = true;
|
||||||
@ -397,7 +390,7 @@ namespace Explorer
|
|||||||
|
|
||||||
for (int i = 0; i < cm.GenericArgs.Length; i++)
|
for (int i = 0; i < cm.GenericArgs.Length; i++)
|
||||||
{
|
{
|
||||||
var type = cm.GenericConstraints[i]?.FullName ?? "None";
|
var type = cm.GenericConstraints[i]?.FullName ?? "Any";
|
||||||
var input = cm.GenericArgInput[i];
|
var input = cm.GenericArgInput[i];
|
||||||
var label = $"<color={UIStyles.Syntax.Class_Instance}>{type}</color>";
|
var label = $"<color={UIStyles.Syntax.Class_Instance}>{type}</color>";
|
||||||
|
|
||||||
@ -462,9 +455,9 @@ namespace Explorer
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var lbl = $"Evaluate (";
|
var lbl = $"Evaluate (";
|
||||||
int args = m_arguments.Length;
|
int len = m_arguments.Length;
|
||||||
if (cm != null) args += cm.GenericArgs.Length;
|
if (cm != null) len += cm.GenericArgs.Length;
|
||||||
lbl += args + " params)";
|
lbl += len + " params)";
|
||||||
|
|
||||||
if (GUILayout.Button(lbl, new GUILayoutOption[] { GUILayout.Width(150) }))
|
if (GUILayout.Button(lbl, new GUILayoutOption[] { GUILayout.Width(150) }))
|
||||||
{
|
{
|
||||||
@ -504,7 +497,7 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
else if (Value == null && !(this is CacheMethod))
|
else if (Value == null && !(this is CacheMethod))
|
||||||
{
|
{
|
||||||
GUILayout.Label("<i>null (" + ValueTypeName + ")</i>", null);
|
GUILayout.Label("<i>null (<color=" + UIStyles.Syntax.Class_Instance + ">" + ValueTypeName + "</color>)</i>", null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -46,14 +46,46 @@ namespace Explorer
|
|||||||
|
|
||||||
public void Evaluate()
|
public void Evaluate()
|
||||||
{
|
{
|
||||||
m_isEvaluating = false;
|
MethodInfo mi;
|
||||||
|
|
||||||
var mi = MemInfo as MethodInfo;
|
|
||||||
object ret = null;
|
|
||||||
|
|
||||||
// Parse generic arguments
|
|
||||||
if (GenericArgs.Length > 0)
|
if (GenericArgs.Length > 0)
|
||||||
{
|
{
|
||||||
|
mi = MakeGenericMethodFromInput();
|
||||||
|
if (mi == null) return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mi = MemInfo as MethodInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
object ret = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, ParseArguments());
|
||||||
|
m_evaluated = true;
|
||||||
|
m_isEvaluating = false;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
MelonLogger.LogWarning($"Exception evaluating: {e.GetType()}, {e.Message}");
|
||||||
|
ReflectionException = ReflectionHelpers.ExceptionToString(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret != null)
|
||||||
|
{
|
||||||
|
m_cachedReturnValue = GetCacheObject(ret);
|
||||||
|
m_cachedReturnValue.UpdateValue();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_cachedReturnValue = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private MethodInfo MakeGenericMethodFromInput()
|
||||||
|
{
|
||||||
|
var mi = MemInfo as MethodInfo;
|
||||||
|
|
||||||
var list = new List<Type>();
|
var list = new List<Type>();
|
||||||
for (int i = 0; i < GenericArgs.Length; i++)
|
for (int i = 0; i < GenericArgs.Length; i++)
|
||||||
{
|
{
|
||||||
@ -72,51 +104,23 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MelonLogger.Log($"Generic argument #{i} '{input}', is not assignable from the generic constraint!");
|
MelonLogger.LogWarning($"Generic argument #{i} '{input}', is not assignable from the generic constraint!");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MelonLogger.Log($"Generic argument #{i}, could not get any type by the name of '{input}'!" +
|
MelonLogger.LogWarning($"Generic argument #{i}, could not get any type by the name of '{input}'!" +
|
||||||
$" Make sure you use the full name, including the NameSpace.");
|
$" Make sure you use the full name, including the NameSpace.");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// make into a generic with type list
|
// make into a generic with type list
|
||||||
mi = mi.MakeGenericMethod(list.ToArray());
|
mi = mi.MakeGenericMethod(list.ToArray());
|
||||||
}
|
|
||||||
|
|
||||||
// Parse arguments
|
return mi;
|
||||||
if (!HasParameters)
|
|
||||||
{
|
|
||||||
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, new object[0]);
|
|
||||||
m_evaluated = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, ParseArguments());
|
|
||||||
m_evaluated = true;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
MelonLogger.Log($"Exception evaluating: {e.GetType()}, {e.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret != null)
|
|
||||||
{
|
|
||||||
m_cachedReturnValue = GetCacheObject(ret);
|
|
||||||
m_cachedReturnValue.UpdateValue();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_cachedReturnValue = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==== GUI DRAW ====
|
// ==== GUI DRAW ====
|
||||||
|
@ -12,6 +12,13 @@ namespace Explorer
|
|||||||
public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod();
|
public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod();
|
||||||
private MethodInfo m_toStringMethod;
|
private MethodInfo m_toStringMethod;
|
||||||
|
|
||||||
|
public override void UpdateValue()
|
||||||
|
{
|
||||||
|
base.UpdateValue();
|
||||||
|
|
||||||
|
GetButtonLabel();
|
||||||
|
}
|
||||||
|
|
||||||
public override void DrawValue(Rect window, float width)
|
public override void DrawValue(Rect window, float width)
|
||||||
{
|
{
|
||||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||||
@ -41,6 +48,8 @@ namespace Explorer
|
|||||||
|
|
||||||
private string GetButtonLabel()
|
private string GetButtonLabel()
|
||||||
{
|
{
|
||||||
|
if (Value == null) return null;
|
||||||
|
|
||||||
string label = (string)ToStringMethod?.Invoke(Value, null) ?? Value.ToString();
|
string label = (string)ToStringMethod?.Invoke(Value, null) ?? Value.ToString();
|
||||||
|
|
||||||
var classColor = ValueType.IsAbstract && ValueType.IsSealed
|
var classColor = ValueType.IsAbstract && ValueType.IsSealed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user