public void CanCreateFunc()
        {
            var       meth  = typeof(TesterClass).GetMethod("TestInt");
            var       func  = LambdaBuilder.CreateFunction(meth);
            const int input = 5;
            var       z     = (int)func(_tester, new object[] { input });

            Assert.IsTrue(_tester.TestIntHit);
            Assert.AreEqual(input * 100, z);
        }
Example #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);
        }
Example #3
0
        public void FuncUsingExpression()
        {
            var        sample = new SampleClass();
            MethodInfo meth   = typeof(SampleClass).GetMethod("GiveAValue");
            var        p1     = new object[] { 100, "hello" };

            Func <object, object[], object> action = LambdaBuilder.CreateFunction(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);
        }