C# has a useful explicit interface feature that lets you create methods that implement interfaces while avoiding potential name conflicts.
public abstract class BaseClass : IDisposable {
public int Value;
void IDisposable.Dispose() => Value = 1;
}
You can even override these methods in subclasses, so long as the subclass also explicitly lists that it implements the interface.
public class SubClass : BaseClass, IDisposable {
void IDisposable.Dispose() => Value = 2;
}
static void Main() {
BaseClass obj = new SubClass();
((IDisposable)obj).Dispose();
Console.WriteLine(obj.Value); // 2
}
From within a subclass, you can usually call base.Whatever
to access the baseclass versions of methods. But with explicit interface implementations, this syntax isn't valid. Also, there's no way to cast your base to the interface in order to call the method.
How do I access the logic within my base class's explicit interface implementations?