BepInEx / HarmonyX

Harmony built on top of MonoMod.RuntimeDetours with additional features
MIT License
373 stars 44 forks source link

How to override explicit interface methods? #90

Closed BlueRaja closed 1 year ago

BlueRaja commented 1 year ago

How do you override a method defined as an explicit interface implementation?

For example:

public interface IMyInterface
{
    bool MyMethod();
}

public class MyClass : IMyInterface
{
    public bool IMyInterface.MyMethod()
    {
        return false;
    }
}

How can we override MyClass.MyMethod? Neither of these work in BepInEx 5.4.21 (HarmonyX 2.7.0):

[HarmonyPatch(typeof(MyClass), "MyMethod")]
[HarmonyPatch(typeof(MyClass), "IMyInterface.MyMethod")]
BlueRaja commented 1 year ago

I figured it out shortly after posting. It has to be

[HarmonyPatch(typeof(MyClass), "Full.Namespace.Goes.Here.IMyInterface.MyMethod")]