public void CanCreateAction() { var meth = typeof(TesterClass).GetMethod("TestVoid"); var action = LambdaBuilder.CreateAction(meth); action(_tester, null); Assert.IsTrue(_tester.TestVoidHit); }
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); }
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); }