public void FuncOneArgCached() { var reflectionCache = new ReflectionCache(); var info = typeof(Foo).GetMethod(nameof(Foo.Method1Arg)); var func = reflectionCache.GetMethodInvoker(info); Assert.IsNotNull(func); var func2 = reflectionCache.GetMethodInvoker(info); Assert.IsNotNull(func2); Assert.AreEqual(func, func2); }
public void GetMethodFuncWithOneArgAndCallIt() { var reflectionCache = new ReflectionCache(); var info = typeof(Foo).GetMethod(nameof(Foo.Method1Arg)); foreach (DelegateCreationMode mode in delegateCreationModes) { InvokeUsingMode(mode); } void InvokeUsingMode(DelegateCreationMode mode) { var func = reflectionCache.GetMethodInvoker(info, mode); Assert.IsNotNull(func, mode.ToString()); var foo = new Foo(); const string expectedValue1 = "Foo"; var funcResult = func(foo, new object[] { expectedValue1 }); Assert.IsTrue(foo.Method1ArgCalled, mode.ToString()); Assert.AreEqual(expectedValue1, foo.Arg1, mode.ToString()); Assert.AreEqual(expectedValue1, funcResult, "Func didn't return the expected value. " + mode); } }
public void GetMethodFuncGenericWithNoArgsAndCallIt() { var reflectionCache = new ReflectionCache(); var info = typeof(Foo).GetMethod(nameof(Foo.Method0Args)); foreach (DelegateCreationMode mode in delegateCreationModes) { InvokeUsingMode(mode); } void InvokeUsingMode(DelegateCreationMode mode) { var func = reflectionCache.GetMethodInvoker <string>(info, mode); Assert.IsNotNull(func, mode.ToString()); var foo = new Foo(); var funcResult = func(foo, new object[] { }); Assert.IsTrue(foo.Method0ArgsCalled, mode.ToString()); Assert.AreEqual(Foo.Method0ArgsResult, funcResult, "Func didn't return the expected value. " + mode); } }
public void GetMethodFuncWithTwoArgsAndCallIt() { var reflectionCache = new ReflectionCache(); var info = typeof(Foo).GetMethod(nameof(Foo.Method2Args)); var func = reflectionCache.GetMethodInvoker(info); Assert.IsNotNull(func); var foo = new Foo(); const string expectedValue1 = "One"; const string expectedValue2 = "Two"; var funcResult = func(foo, new object[] { expectedValue1, expectedValue2 }); Assert.IsTrue(foo.Method2ArgsCalled); Assert.AreEqual(expectedValue1, foo.Arg1); Assert.AreEqual(expectedValue2, foo.Arg2); Assert.AreEqual(expectedValue1, funcResult, "Func didn't return the expected value."); }
public void FuncOneArgCached() { var reflectionCache = new ReflectionCache(); var info = typeof(Foo).GetMethod(nameof(Foo.Method1Arg)); foreach (DelegateCreationMode mode in delegateCreationModes) { InvokeUsingMode(mode); } void InvokeUsingMode(DelegateCreationMode mode) { var func = reflectionCache.GetMethodInvoker(info, mode); Assert.IsNotNull(func, mode.ToString()); var func2 = reflectionCache.GetMethodInvoker(info, mode); Assert.IsNotNull(func2, mode.ToString()); Assert.AreEqual(func, func2, mode.ToString()); } }
public void GetMethodFuncGenericWithNoArgsAndCallIt() { var reflectionCache = new ReflectionCache(); var info = typeof(Foo).GetMethod(nameof(Foo.Method0Args)); var func = reflectionCache.GetMethodInvoker <string>(info); Assert.IsNotNull(func); var foo = new Foo(); var funcResult = func(foo, new object[] { }); Assert.IsTrue(foo.Method0ArgsCalled); Assert.AreEqual(Foo.Method0ArgsResult, funcResult, "Func didn't return the expected value."); }