Skip to content
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

Add Delegate overload #505

Closed
CreateAndInject opened this issue Nov 25, 2022 · 0 comments
Closed

Add Delegate overload #505

CreateAndInject opened this issue Nov 25, 2022 · 0 comments
Assignees

Comments

@CreateAndInject
Copy link

CreateAndInject commented Nov 25, 2022

Current code :

class Demo
{
    static void Test()
    {
        new HarmonyMethod(typeof(Demo).GetMethod("Method1", BindingFlags.NonPublic | BindingFlags.Static));
        new HarmonyMethod(typeof(Demo).GetMethod("Method2", BindingFlags.NonPublic | BindingFlags.Static, null, new[] { typeof(int), typeof(string), typeof(object) }, null));
    }

    static void Method1(int a, string b, object c)
    {
    }

    static void Method2(int a, string b)
    {
    }

    static void Method2(int a, string b, object c)
    {
    }
}

Add Delegate overload

        public HarmonyMethod(Delegate del) : this(del.Method)
        {
        }

in order to support :

class Demo
{
    static void Test()
    {
        new HarmonyMethod(Method1); // C# 10.0 support `Natural type`
        new HarmonyMethod((Action<int, string, object>)Method2);
    }

    static void Method1(int a, string b, object c)
    {
    }

    static void Method2(int a, string b)
    {
    }

    static void Method2(int a, string b, object c)
    {
    }
}
pardeike added a commit that referenced this issue Apr 3, 2023
Add Delegate overloads and implicit casts to HarmonyMethod; Fixes #505
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants