mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-02 03:22:41 +08:00

* Huge restructure/rewrite. No real changes to any functionality, just a cleaner and more manageable project.
72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Reflection;
|
|
using UnityExplorer.UI;
|
|
using UnityExplorer.Core.Unity;
|
|
using UnityEngine;
|
|
|
|
namespace UnityExplorer.UI.CacheObject
|
|
{
|
|
public class CacheProperty : CacheMember
|
|
{
|
|
public override Type FallbackType => (MemInfo as PropertyInfo).PropertyType;
|
|
|
|
public override bool IsStatic => (MemInfo as PropertyInfo).GetAccessors(true)[0].IsStatic;
|
|
|
|
public CacheProperty(PropertyInfo propertyInfo, object declaringInstance, GameObject parent) : base(propertyInfo, declaringInstance, parent)
|
|
{
|
|
this.m_arguments = propertyInfo.GetIndexParameters();
|
|
this.m_argumentInput = new string[m_arguments.Length];
|
|
|
|
CreateIValue(null, propertyInfo.PropertyType);
|
|
}
|
|
|
|
public override void UpdateReflection()
|
|
{
|
|
if (HasParameters && !m_isEvaluating)
|
|
{
|
|
// Need to enter parameters first.
|
|
return;
|
|
}
|
|
|
|
var pi = MemInfo as PropertyInfo;
|
|
|
|
if (pi.CanRead)
|
|
{
|
|
var target = pi.GetAccessors(true)[0].IsStatic ? null : DeclaringInstance;
|
|
|
|
IValue.Value = pi.GetValue(target, ParseArguments());
|
|
|
|
m_evaluated = true;
|
|
ReflectionException = null;
|
|
}
|
|
else
|
|
{
|
|
if (FallbackType == typeof(string))
|
|
{
|
|
IValue.Value = "";
|
|
}
|
|
else if (FallbackType.IsPrimitive)
|
|
{
|
|
IValue.Value = Activator.CreateInstance(FallbackType);
|
|
}
|
|
m_evaluated = true;
|
|
ReflectionException = null;
|
|
}
|
|
}
|
|
|
|
public override void SetValue()
|
|
{
|
|
var pi = MemInfo as PropertyInfo;
|
|
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
|
|
|
|
pi.SetValue(target, IValue.Value, ParseArguments());
|
|
|
|
if (this.ParentInspector?.ParentMember != null)
|
|
this.ParentInspector.ParentMember.SetValue();
|
|
}
|
|
}
|
|
}
|