コード例 #1
0
        public void CanCreateAction()
        {
            var meth = typeof(TesterClass).GetMethod("TestVoid");

            var action = LambdaBuilder.CreateAction(meth);

            action(_tester, null);

            Assert.IsTrue(_tester.TestVoidHit);
        }
コード例 #2
0
        public static MethodDescriptor Create(MethodInfo methodInfo, string key)
        {
            var descriptor = methodInfo.ReturnType == typeof(void)
                                                                                        ? (MethodDescriptor) new ActionDescriptor {
                Delegate = LambdaBuilder.CreateAction(methodInfo)
            }
                                                                                        : new FuncDescriptor {
                Delegate = LambdaBuilder.CreateFunction(methodInfo)
            };

            descriptor.MethodInfo        = methodInfo;
            descriptor.RegisteredTypeKey = key;
            descriptor.ParameterTypes    = methodInfo.GetParameters().Select(p => p.ParameterType).ToArray();

            return(descriptor);
        }
コード例 #3
0
        public void UsingExpression()
        {
            var        sample = new SampleClass();
            MethodInfo meth   = typeof(SampleClass).GetMethod("Update");
            var        p1     = new object[] { 100, "hello" };

            Action <object, object[]> action = LambdaBuilder.CreateAction(meth);

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            for (int i = 0; i < Iterations; i++)
            {
                action(sample, p1);
            }
            stopwatch.Stop();

            Console.WriteLine("Iterations: {0}\tElapsed: {1}", Iterations, stopwatch.ElapsedMilliseconds);
        }