BepInEx / HarmonyX

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

How to override explicit interface methods? #90

Closed BlueRaja closed 11 months ago

BlueRaja commented 11 months 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 11 months ago

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

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