Skip to content

Commit

Permalink
static invoke ext method
Browse files Browse the repository at this point in the history
  • Loading branch information
amazingalek committed Dec 23, 2020
1 parent 84168f9 commit 0ec7c93
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/OWML.ModHelper.Events/HarmonyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void Unpatch<T>(string methodName, PatchType patchType = PatchType.All)
{
_console.WriteLine($"Unpatching {typeof(T).Name}.{methodName}", MessageType.Debug);

var sharedState = (Dictionary<MethodBase, byte[]>)typeof(HarmonySharedState).GetAnyMethod("GetState").Invoke(null, null); // todo TypeExtension
var sharedState = Utils.TypeExtensions.Invoke<Dictionary<MethodBase, byte[]>>(typeof(HarmonySharedState), "GetState");
var method = sharedState.Keys.First(m => m.DeclaringType == typeof(T) && m.Name == methodName);
var patchInfo = PatchInfoSerialization.Deserialize(sharedState.GetValueSafe(method));

Expand Down
3 changes: 3 additions & 0 deletions src/OWML.Utils/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ public static void Invoke(this object obj, string name, params object[] paramete

public static T Invoke<T>(this object obj, string name, params object[] parameters) =>
(T)obj.GetType().GetAnyMethod(name)?.Invoke(obj, parameters);

public static T Invoke<T>(this Type type, string name, params object[] parameters) =>
(T)type.GetAnyMethod(name).Invoke(null, parameters);
}
}

0 comments on commit 0ec7c93

Please sign in to comment.