8000 Add Delegate overloads and implicit casts to HarmonyMethod; Fixes #505 by Banane9 · Pull Request #521 · pardeike/Harmony · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Delegate overloads and implicit casts to HarmonyMethod; Fixes #505 #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Harmony/Public/HarmonyMethod.cs
8000
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