Exemplo n.º 1
0
        private static void RunCastleDynamicProxy()
        {
            var proxy = new Castle.DynamicProxy.ProxyGenerator().CreateInterfaceProxyWithTarget <IProxyImplementInterface>(new TestProxyImplementInterface(), new ValidateInterceptor(), new LogInterceptor());

            CodeTimerAdvance.TimeByConsole("Castle.DynamicProxy.TestMethodWithRefAndOutParameter", COUNT, times =>
            {
                var a      = 1;
                var b      = new string[] { "2" };
                var c      = 0L;
                var result = proxy.TestMethodWithRefAndOutParameter(ref a, ref b, out c);
                if (result != c)
                {
                    throw new ApplicationException("Castle.DynamicProxy.TestMethodWithRefAndOutParameter fail");
                }
            });
            CodeTimerAdvance.TimeByConsole("Castle.DynamicProxy.TestNormalMethod", COUNT, times =>
            {
                var a      = 1;
                var b      = "2";
                var result = proxy.TestNormalMethod(a, b);
                if (result != (a + 1) + Convert.ToInt32(b))
                {
                    throw new ApplicationException($"Castle.DynamicProxy.TestNormalMethod fail, actual:{result}, expected:{(a + 1) + Convert.ToInt32(b)}");
                }
            });
            CodeTimerAdvance.TimeByConsole("Castle.DynamicProxy.TestMethodWithGenericParameter", COUNT, times =>
            {
                var a = 1;
                var b = "2";
                var c = new ValueA {
                    Value = 3
                };
                var result = proxy.TestMethodWithGenericParameter(a, b, new ValueA[] { c });
                if (result != (a + 1) + Convert.ToInt32(b) + c.Value)
                {
                    throw new ApplicationException($"Castle.DynamicProxy.TestMethodWithGenericParameter fail, actual:{result}, expected:{(a + 1) + Convert.ToInt32(b) + c.Value}");
                }
            });
            CodeTimerAdvance.TimeByConsole("Castle.DynamicProxy.TestMethodWithGenericParameterAndRefParameter", COUNT, times =>
            {
                var a = 1;
                var b = "2";
                var c = new ValueA {
                    Value = 3
                };
                var result = proxy.TestMethodWithGenericParameterAndRefParameter(a, b, ref c);
                if (result != c.Value)
                {
                    throw new ApplicationException("Castle.DynamicProxy.TestMethodWithGenericParameterAndRefParameter fail");
                }
            });
        }