Sometimes when working with components created by a library vendor such as DevExpress you want to extend the components. Good vendors will leave plenty of virtual methods for you to put to use, but once in a while you need to hook into an interface method call in a class that implements the method explicitly. You can simply reimplement the interface method, but nine times out of ten you will still want to call the base implementation as though it were virtual. As a matter of fact, it should have been virtual (CA1033).In the meantime, the base implementation is private and you need to use reflection. This class mitigates some of that nuisance so that you don't have to hand-roll reflection code. It hands you an object implementing the interface that calls directly into the private base implementation methods.An example is worth a thousand explanations:interface IExampleInterface{    string InterfaceMethod();}class BaseClass : IExampleInterface{    // The authors of BaseClass did not follow CA1033: Interface methods should be callable by child types    string IExampleInterface.InterfaceMethod()    {        return BaseClass implementation;    }}sealed class CustomizedClass : BaseClass, IExampleInterface{    // We have no choice but to override by implementing the method.    string IExampleInterface.InterfaceMethod()    {        // Now in order to access the base explicit implementation, we use the class below:        return LanguageUtils.ExplicitImplementation<BaseClass, IExampleInterface>(this).InterfaceMethod() +  has been customized.;    }}Surprisingly, there's barely any code:public static class LanguageUtils{    public static TInterface ExplicitImplementation<TBase, TInterface>(TBase @this)        where TBase : TInterface        where TInterface : class    {        return (TInterface)new ExplicitImplementationProxy(typeof(TBase), @this).GetTransparentProxy();    }    private sealed class ExplicitImplementationProxy : RealProxy, IRemotingTypeInfo    {        private readonly Type baseType;        private readonly object instance;        public ExplicitImplementationProxy(Type baseType, object instance) : base(typeof(MarshalByRefObject))        {            this.baseType = baseType;            this.instance = instance;        }        public bool CanCastTo(Type fromType, object o)        {            return fromType.IsInterface && fromType.IsAssignableFrom(baseType);        }        public string TypeName { get; set; }        public override IMessage Invoke(IMessage msg)        {            var methodCall = msg as IMethodCallMessage;            if (methodCall == null) throw new NotSupportedException();            var map = baseType.GetInterfaceMap(methodCall.MethodBase.DeclaringType);            var args = new object[methodCall.Args.Length];            Array.Copy(methodCall.Args, args, args.Length);            return new ReturnMessage(map.TargetMethods[Array.IndexOf(map.InterfaceMethods, (MethodInfo)methodCall.MethodBase)].Invoke(instance, args), args, args.Length, methodCall.LogicalCallContext, methodCall);        }    }}
Facility to run code explicitly implemented in a base class that does not follow CA1033
c#;interface