forked from SteffanDonal/BeatSaber-SaberTailor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReflectionUtil.cs
34 lines (30 loc) · 1.19 KB
/
ReflectionUtil.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Reflection;
namespace SaberTailor
{
internal static class ReflectionUtil
{
public static void SetPrivateField(object obj, string fieldName, object value)
{
var field = obj.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
field.SetValue(obj, value);
}
public static T GetPrivateField<T>(object obj, string fieldName)
{
var field = obj.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
var value = field.GetValue(obj);
return (T)value;
}
public static object GetPrivateField(Type type, object obj, string fieldName)
{
var field = obj.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
var value = field.GetValue(obj);
return value;
}
public static void InvokePrivateMethod(object obj, string methodName, object[] methodParams)
{
var method = obj.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(obj, methodParams);
}
}
}