mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 06:50:18 +00:00
3.0 - unitypackage
This commit is contained in:
48
Runtime/Utilities/ReflectionUtil.cs
Normal file
48
Runtime/Utilities/ReflectionUtil.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class ReflectionUtil
|
||||
{
|
||||
public static void InvokeListClear(object obj, FieldInfo field)
|
||||
{
|
||||
var list = field.GetValue(obj);
|
||||
var method = list.GetType().GetMethod("Clear");
|
||||
method.Invoke(list, new object[] { });
|
||||
}
|
||||
public static int InvokeListCount(object obj, FieldInfo field)
|
||||
{
|
||||
var list = field.GetValue(obj);
|
||||
return (int)list.GetType().GetProperty("Count").GetValue(list);
|
||||
}
|
||||
|
||||
public static void InvokeListAdd(object obj, FieldInfo field, object item)
|
||||
{
|
||||
var list = field.GetValue(obj);
|
||||
var method = list.GetType().GetMethod("Add");
|
||||
method.Invoke(list, new object[] { item });
|
||||
}
|
||||
|
||||
public static T InvokeListGet<T>(object obj, FieldInfo field, int i)
|
||||
{
|
||||
var list = field.GetValue(obj);
|
||||
var item = list.GetType().GetProperty("Item").GetValue(list, new object[] { i });
|
||||
return (T)item;
|
||||
}
|
||||
|
||||
|
||||
public static void InvokeListAddTo<T>(object obj, FieldInfo field, Action<T> callback)
|
||||
{
|
||||
var list = field.GetValue(obj);
|
||||
var listType = list.GetType();
|
||||
var count = Convert.ToInt32(listType.GetProperty("Count").GetValue(list));
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var item = listType.GetProperty("Item").GetValue(list, new object[] { i });
|
||||
callback((T)item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user