public void InitialSetup() { _testClass = new TestClass(); _methodForGenerating = _testClass.GetType().GetMethod(nameof(TestClass.MethodForGenerating)); _methodForCaching = _testClass.GetType().GetMethod(nameof(TestClass.MethodForCaching)); _cachedCompiledMethod = _methodForCaching.Compile(); _cachedCompiledMethodWithInstance = _cachedCompiledMethod.WithInstance(_testClass); }
/// <summary> /// Invokes intercepted methods using reflection /// </summary> /// <param name="proxy">proxy object</param> /// <param name="target">target object to invoke method on</param> /// <param name="targetType">target type</param> /// <param name="targetMethod">taget method to invoke</param> /// <param name="proxyMethod">The method to invoke on proxy.</param> /// <param name="args">method arguments</param> /// <param name="interceptors">interceptor chain</param> /// <returns>value returned by invocation chain</returns> public object Invoke(object proxy, object target, Type targetType, MethodInfo targetMethod, MethodInfo proxyMethod, object[] args, IList interceptors) { IMethodInvocation invocation = null; if (UseDynamicReflection) { invocation = new DynamicMethodInvocation( proxy, target, targetMethod, proxyMethod, args, targetType, interceptors); } else { invocation = new ReflectiveMethodInvocation( proxy, target, targetMethod, proxyMethod, args, targetType, interceptors); } return invocation.Proceed(); }