mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +08:00
67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
using UnityExplorer.Inspectors;
|
|
|
|
namespace UnityExplorer.CacheObject
|
|
{
|
|
public class CacheProperty : CacheMember
|
|
{
|
|
public PropertyInfo PropertyInfo { get; internal set; }
|
|
public override Type DeclaringType => PropertyInfo.DeclaringType;
|
|
public override bool CanWrite => PropertyInfo.CanWrite;
|
|
public override bool IsStatic => m_isStatic ?? (bool)(m_isStatic = PropertyInfo.GetAccessors(true)[0].IsStatic);
|
|
private bool? m_isStatic;
|
|
|
|
public override bool ShouldAutoEvaluate => !HasArguments;
|
|
|
|
public CacheProperty(PropertyInfo pi)
|
|
{
|
|
this.PropertyInfo = pi;
|
|
}
|
|
|
|
public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
|
{
|
|
base.SetInspectorOwner(inspector, member);
|
|
|
|
Arguments = PropertyInfo.GetIndexParameters();
|
|
}
|
|
|
|
protected override object TryEvaluate()
|
|
{
|
|
try
|
|
{
|
|
object ret;
|
|
if (HasArguments)
|
|
ret = PropertyInfo.GetValue(DeclaringInstance, this.Evaluator.TryParseArguments());
|
|
else
|
|
ret = PropertyInfo.GetValue(DeclaringInstance, null);
|
|
LastException = null;
|
|
return ret;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LastException = ex;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
protected override void TrySetValue(object value)
|
|
{
|
|
if (!CanWrite)
|
|
return;
|
|
|
|
try
|
|
{
|
|
bool _static = PropertyInfo.GetAccessors(true)[0].IsStatic;
|
|
|
|
if (HasArguments)
|
|
PropertyInfo.SetValue(DeclaringInstance, value, Evaluator.TryParseArguments());
|
|
else
|
|
PropertyInfo.SetValue(DeclaringInstance, value, null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ExplorerCore.LogWarning(ex);
|
|
}
|
|
}
|
|
}
|
|
}
|