2021-04-27 21:22:48 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
2022-02-19 17:50:10 +11:00
|
|
|
|
using UnityEngine;
|
2021-06-30 07:49:58 +10:00
|
|
|
|
using UnityExplorer.Inspectors;
|
2022-02-19 17:50:10 +11:00
|
|
|
|
using UnityExplorer.Runtime;
|
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 CacheProperty : CacheMember
|
|
|
|
|
{
|
|
|
|
|
public PropertyInfo PropertyInfo { get; internal set; }
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public override Type DeclaringType => PropertyInfo.DeclaringType;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
public override bool CanWrite => PropertyInfo.CanWrite;
|
2021-05-05 21:27:09 +10:00
|
|
|
|
public override bool IsStatic => m_isStatic ?? (bool)(m_isStatic = PropertyInfo.GetAccessors(true)[0].IsStatic);
|
|
|
|
|
private bool? m_isStatic;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
2021-04-28 20:47:48 +10:00
|
|
|
|
public override bool ShouldAutoEvaluate => !HasArguments;
|
|
|
|
|
|
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 = PropertyInfo.GetIndexParameters();
|
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-29 14:50:21 +10:00
|
|
|
|
object ret;
|
2021-05-04 20:10:46 +10:00
|
|
|
|
if (HasArguments)
|
2021-05-29 14:50:21 +10:00
|
|
|
|
ret = PropertyInfo.GetValue(DeclaringInstance, this.Evaluator.TryParseArguments());
|
2021-06-05 19:36:09 +10:00
|
|
|
|
else
|
2021-05-29 14:50:21 +10:00
|
|
|
|
ret = PropertyInfo.GetValue(DeclaringInstance, null);
|
2021-05-04 20:10:46 +10:00
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (!CanWrite)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-05-04 20:10:46 +10:00
|
|
|
|
bool _static = PropertyInfo.GetAccessors(true)[0].IsStatic;
|
2021-04-29 21:01:08 +10:00
|
|
|
|
|
2021-05-04 20:10:46 +10:00
|
|
|
|
if (HasArguments)
|
2021-05-06 06:36:39 +10:00
|
|
|
|
PropertyInfo.SetValue(DeclaringInstance, value, Evaluator.TryParseArguments());
|
2021-05-04 20:10:46 +10:00
|
|
|
|
else
|
2021-05-06 06:36:39 +10:00
|
|
|
|
PropertyInfo.SetValue(DeclaringInstance, value, null);
|
2021-04-29 21:01:08 +10:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.LogWarning(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
}
|