mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 07:20:08 +00:00
3.0 - inspector
This commit is contained in:
@@ -9,10 +9,18 @@ namespace XCharts.Runtime
|
||||
{
|
||||
public static class ReflectionUtil
|
||||
{
|
||||
private static Dictionary<object, MethodInfo> listClearMethodInfoCaches = new Dictionary<object, MethodInfo>();
|
||||
private static Dictionary<object, MethodInfo> listAddMethodInfoCaches = new Dictionary<object, MethodInfo>();
|
||||
|
||||
public static void InvokeListClear(object obj, FieldInfo field)
|
||||
{
|
||||
var list = field.GetValue(obj);
|
||||
var method = list.GetType().GetMethod("Clear");
|
||||
MethodInfo method;
|
||||
if (!listClearMethodInfoCaches.TryGetValue(list, out method))
|
||||
{
|
||||
method = list.GetType().GetMethod("Clear");
|
||||
listClearMethodInfoCaches[list] = method;
|
||||
}
|
||||
method.Invoke(list, new object[] { });
|
||||
}
|
||||
public static int InvokeListCount(object obj, FieldInfo field)
|
||||
@@ -24,7 +32,12 @@ namespace XCharts.Runtime
|
||||
public static void InvokeListAdd(object obj, FieldInfo field, object item)
|
||||
{
|
||||
var list = field.GetValue(obj);
|
||||
var method = list.GetType().GetMethod("Add");
|
||||
MethodInfo method;
|
||||
if (!listAddMethodInfoCaches.TryGetValue(list, out method))
|
||||
{
|
||||
method = list.GetType().GetMethod("Add");
|
||||
listAddMethodInfoCaches[list] = method;
|
||||
}
|
||||
method.Invoke(list, new object[] { item });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user