Beispiel #1
0
        public void AddForwardingExplicitInterfaceMethod()
        {
            var proxyBuilder = new ForwardingProxyBuilder("AddForwardingExplicitInterfaceMethod",
                                                          ModuleScope, typeof(ProxiedChild), new[] { typeof(IAmbigous1) });

            var methodInfo = typeof(IAmbigous1).GetMethod("StringTimes");

            proxyBuilder.AddForwardingExplicitInterfaceMethod(methodInfo);

            // Create proxy instance, initializing it with class to be proxied
            var    proxied = new ProxiedChild();
            object proxy   = proxyBuilder.CreateInstance(proxied);

            Assert.That(((IAmbigous1)proxied).StringTimes("aBc", 4), Is.EqualTo("aBcaBcaBcaBc"));
            Assert.That(((IAmbigous1)proxy).StringTimes("aBc", 4), Is.EqualTo("aBcaBcaBcaBc"));
        }
Beispiel #2
0
        public void AddForwardingMethod_GenericClass()
        {
            var proxyBuilder = new ForwardingProxyBuilder("AddForwardingMethod_GenericClass",
                                                          ModuleScope, typeof(ProxiedChildGeneric <ProxiedChild, double>), new Type[0]);
            var methodInfo    = typeof(ProxiedChildGeneric <ProxiedChild, double>).GetMethod("ToStringKebap");
            var methodEmitter = proxyBuilder.AddForwardingMethod(methodInfo);

            // Create proxy instance, initializing it with class to be proxied
            var    proxied = new ProxiedChildGeneric <ProxiedChild, double> ("PCG", new ProxiedChild("PC"), 123.456);
            object proxy   = proxyBuilder.CreateInstance(proxied);

            // Added by FS
            AssertMethodInfoEqual(methodEmitter.MethodBuilder, methodInfo);

            var proxyMethodInfo = proxy.GetType().GetMethod("ToStringKebap");

            AssertMethodInfoEqual(proxyMethodInfo, methodInfo);
            Assert.That(proxyMethodInfo.Invoke(proxy, new object[] { 9800 }), Is.EqualTo("ProxiedChild: PCG_[Proxied: PC]_123.456_9800"));
        }