/// <summary> /// Modifies the current <paramref name="target"/> to support third-party method call interception for all method calls made inside the target. /// </summary> /// <param name="target">The target object.</param> /// <param name="methodCallFilter">The <see cref="IMethodCallFilter"/> instance that determines the method calls that will be intercepted.</param> /// <param name="hostMethodFilter">The <see cref="IMethodFilter"/> instance that determines the host method calls that will be modified</param> public static void InterceptMethodCalls(this IReflectionVisitable target, IMethodCallFilter methodCallFilter, IMethodFilter hostMethodFilter) { var rewriter = new InterceptMethodCalls(methodCallFilter); target.Accept(new ImplementModifiableType(GetDefaultTypeFilter())); target.WeaveWith(rewriter, hostMethodFilter.ShouldWeave); }
/// <summary> /// Modifies the current <paramref name="target" /> to support third-party method call interception for all method /// calls made inside the target. /// </summary> /// <param name="target">The target object.</param> /// <param name="methodCallFilter"> /// The <see cref="IMethodCallFilter" /> instance that determines the method calls that will /// be intercepted. /// </param> /// <param name="hostMethodFilter"> /// The <see cref="IMethodFilter" /> instance that determines the host method calls that /// will be modified /// </param> public static void InterceptMethodCalls(this TypeDefinition target, IMethodCallFilter methodCallFilter, IMethodFilter hostMethodFilter) { var rewriter = new InterceptMethodCalls(methodCallFilter); target.Accept(new ImplementModifiableType(GetDefaultTypeFilter())); target.WeaveWith(rewriter); }
/// <summary> /// Modifies the current <paramref name="target" /> to support third-party method call interception for all method /// calls made inside the target. /// </summary> /// <param name="target">The target object.</param> /// <param name="methodCallFilter"> /// The <see cref="IMethodCallFilter" /> instance that determines the method calls that will /// be intercepted. /// </param> /// <param name="hostMethodFilter"> /// The <see cref="IMethodFilter" /> instance that determines the host method calls that /// will be modified /// </param> public static void InterceptMethodCalls(this AssemblyDefinition target, IMethodCallFilter methodCallFilter, IMethodFilter hostMethodFilter) { var module = target.MainModule; var methods = module.Types.Where(t => GetDefaultTypeFilter()(t)).SelectMany(t => t.Methods) .Where(hostMethodFilter.ShouldWeave).ToArray(); var rewriter = new InterceptMethodCalls(methodCallFilter); target.Accept(new ImplementModifiableType(GetDefaultTypeFilter())); target.WeaveWith(rewriter); }
public InterceptMethodCalls(IMethodCallFilter callFilter) { _callFilter = callFilter; }
public InterceptMethodCalls(Func<MethodReference, bool> hostMethodFilter, Func<MethodReference, bool> methodCallFilter) { _callFilter = new MethodCallFilterAdapter(hostMethodFilter, methodCallFilter); }
public InterceptMethodCalls(Func <MethodReference, bool> hostMethodFilter, Func <MethodReference, bool> methodCallFilter) { _callFilter = new MethodCallFilterAdapter(hostMethodFilter, methodCallFilter); }