Skip to content

Commit

Permalink
Merge pull request #521 from Banane9/add-delegate-overload-505
Browse files Browse the repository at this point in the history
Add Delegate overloads and implicit casts to HarmonyMethod; Fixes #505
  • Loading branch information
pardeike committed Apr 3, 2023
2 parents fc19016 + e37d9ec commit 933620d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Harmony/Public/HarmonyMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public HarmonyMethod(MethodInfo method)
ImportMethod(method);
}

/// <summary>Creates a patch from a given method</summary>
/// <param name="delegate">The original method</param>
///
public HarmonyMethod(Delegate @delegate)
: this(@delegate.Method)
{ }

/// <summary>Creates a patch from a given method</summary>
/// <param name="method">The original method</param>
/// <param name="priority">The patch <see cref="Priority"/></param>
Expand All @@ -104,6 +111,17 @@ public HarmonyMethod(MethodInfo method, int priority = -1, string[] before = nul
this.debug = debug;
}

/// <summary>Creates a patch from a given method</summary>
/// <param name="delegate">The original method</param>
/// <param name="priority">The patch <see cref="Priority"/></param>
/// <param name="before">A list of harmony IDs that should come after this patch</param>
/// <param name="after">A list of harmony IDs that should come before this patch</param>
/// <param name="debug">Set to true to generate debug output</param>
///
public HarmonyMethod(Delegate @delegate, int priority = -1, string[] before = null, string[] after = null, bool? debug = null)
: this(@delegate.Method, priority, before, after, debug)
{ }

/// <summary>Creates a patch from a given method</summary>
/// <param name="methodType">The patch class/type</param>
/// <param name="methodName">The patch method name</param>
Expand Down Expand Up @@ -177,6 +195,22 @@ internal string Description()
var aName = argumentTypes is object ? argumentTypes.Description() : "undefined";
return $"(class={cName}, methodname={mName}, type={tName}, args={aName})";
}

/// <summary>Creates a patch from a given method</summary>
/// <param name="method">The original method</param>
///
public static implicit operator HarmonyMethod(MethodInfo method)
{
return new HarmonyMethod(method);
}

/// <summary>Creates a patch from a given method</summary>
/// <param name="delegate">The original method</param>
///
public static implicit operator HarmonyMethod(Delegate @delegate)
{
return new HarmonyMethod(@delegate);
}
}

/// <summary>Annotation extensions</summary>
Expand Down

0 comments on commit 933620d

Please sign in to comment.