Export to GitHub

linfu - issue #39

Generic Methods with Constraints don't work through proxies. ie.. this test fails.


Posted on Nov 12, 2009 by Happy Bear
    public interface IRestrictedGeneric
    {
        T DoSomething<T>() where T : Entity;
    }

    public class RestrictedGeneric: IRestrictedGeneric
    {
        public T DoSomething<T>() where T : Entity
        {
            T foo = default(T);
            foo.ID = 10;
            return foo;
        }
    }

    public class Entity
    {
        public int ID {get;set;}
    }

    public class Banana:Entity
    {

    }

    public class Interceptor : IInterceptor
    {
        public object Intercept(InvocationInfo info)
        {
            return null;
        }
    }

    [Test]
    public void TSC_WithGenericMethodsWithRestrictionsS()
    {
        var proxy = new

ProxyFactory().CreateProxy(typeof(IRestrictedGeneric), new Interceptor()); ((IRestrictedGeneric)proxy).DoSomething<Banana>(); }


System.Security.VerificationException: Method NDependencyInjection.Tests.ConduitTests+IRestrictedGeneric.DoSomething: type argument 'T0' violates the constraint of type parameter 'T'. at IRestrictedGenericProxy.DoSomething<T0>() at NDependencyInjection.Tests.ConduitTests.TSC_WithGenericMethodsWithRestrictionsS() in ConduitTests.cs: line 192

Status: New

Labels:
Type-Defect Priority-Medium