2020-11-09 21:38:25 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using UnityExplorer.UI;
|
|
|
|
|
using UnityExplorer.Helpers;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.Inspectors.Reflection
|
|
|
|
|
{
|
|
|
|
|
public class CacheProperty : CacheMember
|
|
|
|
|
{
|
|
|
|
|
public override bool IsStatic => (MemInfo as PropertyInfo).GetAccessors()[0].IsStatic;
|
|
|
|
|
|
|
|
|
|
public CacheProperty(PropertyInfo propertyInfo, object declaringInstance) : base(propertyInfo, declaringInstance)
|
|
|
|
|
{
|
|
|
|
|
this.m_arguments = propertyInfo.GetIndexParameters();
|
|
|
|
|
this.m_argumentInput = new string[m_arguments.Length];
|
|
|
|
|
|
|
|
|
|
base.InitValue(null, propertyInfo.PropertyType);
|
|
|
|
|
|
|
|
|
|
UpdateValue();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-11 20:16:43 +11:00
|
|
|
|
public override void UpdateReflection()
|
2020-11-09 21:38:25 +11:00
|
|
|
|
{
|
|
|
|
|
if (HasParameters && !m_isEvaluating)
|
|
|
|
|
{
|
|
|
|
|
// Need to enter parameters first.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
var pi = MemInfo as PropertyInfo;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
if (pi.CanRead)
|
|
|
|
|
{
|
|
|
|
|
var target = pi.GetAccessors(true)[0].IsStatic ? null : DeclaringInstance;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
IValue.Value = pi.GetValue(target, ParseArguments());
|
2020-11-11 20:16:43 +11:00
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
m_evaluated = true;
|
|
|
|
|
ReflectionException = null;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
}
|
2020-11-12 16:15:41 +11:00
|
|
|
|
else // create a dummy value for Write-Only properties.
|
2020-11-09 21:38:25 +11:00
|
|
|
|
{
|
2020-11-12 16:15:41 +11:00
|
|
|
|
if (IValue.ValueType == typeof(string))
|
|
|
|
|
IValue.Value = "";
|
|
|
|
|
else
|
|
|
|
|
IValue.Value = Activator.CreateInstance(IValue.ValueType);
|
2020-11-09 21:38:25 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetValue()
|
|
|
|
|
{
|
|
|
|
|
var pi = MemInfo as PropertyInfo;
|
|
|
|
|
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
|
|
|
|
|
|
|
|
|
|
pi.SetValue(target, IValue.Value, ParseArguments());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|