2021-04-27 21:22:48 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
2021-05-05 21:27:09 +10:00
|
|
|
|
using UnityExplorer.UI.Inspectors;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
2021-05-05 21:27:09 +10:00
|
|
|
|
namespace UnityExplorer.UI.CacheObject
|
2021-04-27 21:22:48 +10:00
|
|
|
|
{
|
|
|
|
|
public class CacheMethod : CacheMember
|
|
|
|
|
{
|
|
|
|
|
public MethodInfo MethodInfo { get; internal set; }
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public override Type DeclaringType => MethodInfo.DeclaringType;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
public override bool CanWrite => false;
|
2021-05-05 21:27:09 +10:00
|
|
|
|
public override bool IsStatic => MethodInfo.IsStatic;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
2021-04-28 20:47:48 +10:00
|
|
|
|
public override bool ShouldAutoEvaluate => false;
|
|
|
|
|
|
2021-04-30 21:34:50 +10:00
|
|
|
|
public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
2021-04-27 21:22:48 +10:00
|
|
|
|
{
|
2021-04-30 21:34:50 +10:00
|
|
|
|
base.SetInspectorOwner(inspector, member);
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
2021-04-28 20:47:48 +10:00
|
|
|
|
Arguments = MethodInfo.GetParameters();
|
2021-05-04 20:10:46 +10:00
|
|
|
|
if (MethodInfo.IsGenericMethod)
|
|
|
|
|
GenericArguments = MethodInfo.GetGenericArguments();
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-04 20:10:46 +10:00
|
|
|
|
protected override object TryEvaluate()
|
2021-04-27 21:22:48 +10:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-05-04 20:10:46 +10:00
|
|
|
|
var methodInfo = MethodInfo;
|
|
|
|
|
|
|
|
|
|
if (methodInfo.IsGenericMethod)
|
|
|
|
|
methodInfo = MethodInfo.MakeGenericMethod(Evaluator.TryParseGenericArguments());
|
|
|
|
|
|
|
|
|
|
var target = MethodInfo.IsStatic ? null : Owner.Target.TryCast(DeclaringType);
|
|
|
|
|
|
|
|
|
|
if (Arguments.Length > 0)
|
|
|
|
|
return methodInfo.Invoke(target, Evaluator.TryParseArguments());
|
|
|
|
|
|
|
|
|
|
var ret = methodInfo.Invoke(target, new object[0]);
|
|
|
|
|
|
|
|
|
|
HadException = false;
|
|
|
|
|
LastException = null;
|
|
|
|
|
return ret;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
HadException = true;
|
|
|
|
|
LastException = ex;
|
2021-05-04 20:10:46 +10:00
|
|
|
|
return null;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-29 21:01:08 +10:00
|
|
|
|
|
|
|
|
|
protected override void TrySetValue(object value) => throw new NotImplementedException("You can't set a method");
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
}
|