2021-04-27 21:22:48 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
2021-06-30 07:49:58 +10:00
|
|
|
|
using UnityExplorer.Inspectors;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
2021-06-30 07:49:58 +10:00
|
|
|
|
namespace UnityExplorer.CacheObject
|
2021-04-27 21:22:48 +10:00
|
|
|
|
{
|
|
|
|
|
public class CacheField : CacheMember
|
|
|
|
|
{
|
|
|
|
|
public FieldInfo FieldInfo { get; internal set; }
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public override Type DeclaringType => FieldInfo.DeclaringType;
|
2021-05-05 21:27:09 +10:00
|
|
|
|
public override bool IsStatic => FieldInfo.IsStatic;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
public override bool CanWrite => m_canWrite ?? (bool)(m_canWrite = !(FieldInfo.IsLiteral && !FieldInfo.IsInitOnly));
|
|
|
|
|
private bool? m_canWrite;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
2021-04-28 20:47:48 +10:00
|
|
|
|
public override bool ShouldAutoEvaluate => true;
|
|
|
|
|
|
2022-03-14 05:20:43 +11:00
|
|
|
|
public CacheField(FieldInfo fi)
|
|
|
|
|
{
|
|
|
|
|
this.FieldInfo = fi;
|
|
|
|
|
}
|
|
|
|
|
|
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-05-04 20:10:46 +10:00
|
|
|
|
protected override object TryEvaluate()
|
2021-04-27 21:22:48 +10:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-05-06 04:02:42 +10:00
|
|
|
|
var ret = FieldInfo.GetValue(DeclaringInstance);
|
2021-05-04 20:10:46 +10:00
|
|
|
|
LastException = null;
|
|
|
|
|
return ret;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-05-06 06:36:39 +10:00
|
|
|
|
FieldInfo.SetValue(DeclaringInstance, value);
|
2021-04-29 21:01:08 +10:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.LogWarning(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
}
|