philiplaureano / LinFu

A framework that adds mixins, inversion of control, DbC, and other language features to the Common Language Runtime.
http://www.codeproject.com/KB/cs/LinFuPart1.aspx
206 stars 30 forks source link

Proxy creation fails for classes having explicitly implemented interfaces #20

Open GhoSe opened 12 years ago

GhoSe commented 12 years ago

The title says more or less all. A little sample:

    [TestClass]
    public class LinFuProxyTests
    {
        [TestMethod]
        public void CreateProxyTest()
        {
            var target = new SampleClass();
            var factory = new ProxyFactory();
            var interceptor = new SampleInterceptor(target);

            var proxy = factory.CreateProxy<SampleClass>(interceptor);
        }
    }

    public class SampleClass : ICloneable
    {
        object ICloneable.Clone()
        {
            return new SampleClass();
        }
    }

    public class SampleInterceptor : IInvokeWrapper
    {
        public SampleInterceptor(object target)
        {
            this.Target = target;
        }

        public object Target { get; private set; }

        object IInvokeWrapper.DoInvoke(IInvocationInfo info)
        {
            return null;
        }

        void IBeforeInvoke.BeforeInvoke(IInvocationInfo info)
        {
        }

        void IAfterInvoke.AfterInvoke(IInvocationInfo info, object returnValue)
        {
        }
    }

Result of the unit test is:

Test method LinFuProxyTests.CreateProxyTest threw exception: System.ArgumentNullException: Value cannot be null. Parameter name: type at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at LinFu.Proxy.Interfaces.ProxyFactoryExtensions.CreateProxy(IProxyFactory factory, Type instanceType, IInterceptor interceptor, Type[] baseInterfaces) at LinFu.Proxy.Interfaces.ProxyFactoryExtensions.CreateProxy(IProxyFactory factory, Type instanceType, IInvokeWrapper wrapper, Type[] baseInterfaces) at LinFu.Proxy.Interfaces.ProxyFactoryExtensions.CreateProxy(IProxyFactory factory, IInvokeWrapper wrapper, Type[] baseInterfaces) at LinFuProxyTests.CreateProxyTest() in LinFuProxyTests.cs: line 28