From 0ec7c93338cfa9fd0c9ba55d100428cf6fa1666d Mon Sep 17 00:00:00 2001 From: Aleksander Waage Date: Wed, 23 Dec 2020 10:42:04 +0100 Subject: [PATCH] static invoke ext method --- src/OWML.ModHelper.Events/HarmonyHelper.cs | 2 +- src/OWML.Utils/TypeExtensions.cs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/OWML.ModHelper.Events/HarmonyHelper.cs b/src/OWML.ModHelper.Events/HarmonyHelper.cs index 35da5f521..4e939b190 100644 --- a/src/OWML.ModHelper.Events/HarmonyHelper.cs +++ b/src/OWML.ModHelper.Events/HarmonyHelper.cs @@ -97,7 +97,7 @@ public void Unpatch(string methodName, PatchType patchType = PatchType.All) { _console.WriteLine($"Unpatching {typeof(T).Name}.{methodName}", MessageType.Debug); - var sharedState = (Dictionary)typeof(HarmonySharedState).GetAnyMethod("GetState").Invoke(null, null); // todo TypeExtension + var sharedState = Utils.TypeExtensions.Invoke>(typeof(HarmonySharedState), "GetState"); var method = sharedState.Keys.First(m => m.DeclaringType == typeof(T) && m.Name == methodName); var patchInfo = PatchInfoSerialization.Deserialize(sharedState.GetValueSafe(method)); diff --git a/src/OWML.Utils/TypeExtensions.cs b/src/OWML.Utils/TypeExtensions.cs index ffff2fbbd..2f840458d 100644 --- a/src/OWML.Utils/TypeExtensions.cs +++ b/src/OWML.Utils/TypeExtensions.cs @@ -44,5 +44,8 @@ public static void Invoke(this object obj, string name, params object[] paramete public static T Invoke(this object obj, string name, params object[] parameters) => (T)obj.GetType().GetAnyMethod(name)?.Invoke(obj, parameters); + + public static T Invoke(this Type type, string name, params object[] parameters) => + (T)type.GetAnyMethod(name).Invoke(null, parameters); } } \ No newline at end of file