Example #1
0
        public void LCGDoubleCallFuncNoArgInt32()
        {
            Func <Object, Int32> func = ExpressionTreeReflection.ReflectFunction <Int32>(suType, "AMethod");

            func = LCGReflection.ReflectFunction <Int32>(suType, "AMethod");
            Assert.That(func(suInstance), Is.EqualTo(1));
        }
Example #2
0
        public void TestPerformanceGain2()
        {
            Func <Object, String, Int32> func = ExpressionTreeReflection.ReflectFunction <String, Int32>(suType, "BMethod");
            MethodInfo minfo       = suType.GetMethod("BMethod", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(String) }, null);
            Double     RefDuration = With.PerformanceCounter(() => { for (Int32 I = 0; I < 100000; ++I)
                                                                     {
                                                                         minfo.Invoke(suInstance, new Object[] { "test" });
                                                                     }
                                                             });
            Double ExpDuration = With.PerformanceCounter(() => { for (Int32 I = 0; I < 100000; ++I)
                                                                 {
                                                                     func(suInstance, "test");
                                                                 }
                                                         });

            Console.WriteLine("Reflection = {0} Expression Tree {1}", RefDuration, ExpDuration);
        }
Example #3
0
        public void TestPerformanceGain()
        {
            Func <Object, Int32> func    = ExpressionTreeReflection.ReflectFunction <Int32>(suType, "AMethod");
            Func <Object, Int32> lcgfunc = LCGReflection.ReflectFunction <Int32>(suType, "AMethod");
            MethodInfo           minfo   = suType.GetMethod("AMethod", BindingFlags.Public | BindingFlags.Instance);
            Double RefDuration           = With.PerformanceCounter(() => { for (Int32 I = 0; I < 1000000; ++I)
                                                                           {
                                                                               minfo.Invoke(suInstance, new Object[] { });
                                                                           }
                                                                   });
            Double ExpDuration = With.PerformanceCounter(() => { for (Int32 I = 0; I < 1000000; ++I)
                                                                 {
                                                                     func(suInstance);
                                                                 }
                                                         });
            Double LcgDuration = With.PerformanceCounter(() => { for (Int32 I = 0; I < 1000000; ++I)
                                                                 {
                                                                     lcgfunc(suInstance);
                                                                 }
                                                         });

            Console.WriteLine("Reflection = {0} Expression Tree {1} LCG {2}", RefDuration, ExpDuration, LcgDuration);
        }
Example #4
0
        public void TestFuncNoArgString()
        {
            Func <Object, String> func = ExpressionTreeReflection.ReflectFunction <String>(suType, "SMethod");

            Assert.That(func(suInstance), Is.EqualTo("Hello"));
        }
Example #5
0
        public void TestFuncOneArgInt32Overload()
        {
            Func <Object, String, Int32> func = ExpressionTreeReflection.ReflectFunction <String, Int32>(suType, "BMethod");

            Assert.That(func(suInstance, "test"), Is.EqualTo(4));
        }
Example #6
0
        public void TestFuncOneArgInt32()
        {
            Func <Object, Int32, Int32> func = ExpressionTreeReflection.ReflectFunction <Int32, Int32>(suType, "BMethod");

            Assert.That(func(suInstance, 4), Is.EqualTo(8));
        }