Files
2026-03-04 09:37:33 +08:00

145 lines
2.8 KiB
C#

using System;
using System.Reflection;
using UnityEngine;
namespace DebuggingEssentials
{
public class MemberData
{
public MemberType memberType;
public MemberInfo member;
public FieldInfo field;
public PropertyInfo prop;
public MethodInfo method;
public ParameterInfo[] parameters;
public bool validInvokeParameters;
public bool isStatic;
public bool isConstant;
public bool isString;
public bool isClass;
public bool isStruct;
public bool isArray;
public bool isInterface;
public Type type;
public Scope scope;
public string name;
public string typeName;
public string scopeToolTip;
public Color scopeColor;
public MemberData(Type objType, MemberInfo member, MemberType memberType, Color colorPublic, Color colorProtected, Color colorPrivate)
{
this.member = member;
this.memberType = memberType;
switch (memberType)
{
case MemberType.Field:
field = (FieldInfo)member;
name = field.Name;
type = field.FieldType;
isStatic = field.IsStatic;
isConstant = field.IsLiteral;
if (field.IsPublic)
{
scope = Scope.Public;
}
else if (field.IsFamily)
{
scope = Scope.Protected;
}
else if (field.IsPrivate)
{
scope = Scope.Private;
}
break;
case MemberType.Property:
prop = (PropertyInfo)member;
name = prop.Name;
type = prop.PropertyType;
method = prop.GetGetMethod(nonPublic: true);
if (method == null)
{
method = prop.GetSetMethod(nonPublic: true);
}
if (method != null)
{
isStatic = method.IsStatic;
if (method.IsPublic)
{
scope = Scope.Public;
}
else if (method.IsPrivate)
{
scope = Scope.Private;
}
else if (method.IsFamily)
{
scope = Scope.Protected;
}
}
break;
default:
method = (MethodInfo)member;
parameters = method.GetParameters();
validInvokeParameters = RuntimeConsole.ValidParams(type, method, parameters, logFailed: false);
name = method.ToString();
type = method.DeclaringType;
isStatic = method.IsStatic;
if (method.IsPublic)
{
scope = Scope.Public;
}
else if (method.IsPrivate)
{
scope = Scope.Private;
}
else if (method.IsFamily)
{
scope = Scope.Protected;
}
break;
}
isString = type == typeof(string);
isClass = type.IsClass;
isStruct = type.IsValueType && !type.IsPrimitive && !type.IsEnum;
isArray = type.IsArray;
isInterface = type.IsInterface;
typeName = "(" + type.Name + ")";
if (scope == Scope.Public)
{
scopeColor = colorPublic;
scopeToolTip = "Is Public";
}
else if (scope == Scope.Protected)
{
scopeColor = colorProtected;
scopeToolTip = "Is Protected";
}
else
{
scopeColor = colorPrivate;
scopeToolTip = "Is Private";
}
}
}
}