/// <summary> /// Modifies the current <paramref name="target"/> to support third-party method call interception. /// </summary> /// <param name="target">The target object.</param> /// <param name="typeFilter">The filter that will determine the target types that will be modified.</param> /// <param name="hostMethodFilter">The filter that will determine the methods that will be modified on the target type.</param> /// <param name="methodCallFilter">The filter that will determine which third-party methods will be intercepted on the target type.</param> public static void InterceptMethodCalls(this IReflectionVisitable target, Func <TypeReference, bool> typeFilter, Func <MethodReference, bool> hostMethodFilter, Func <MethodReference, bool> methodCallFilter) { var rewriter = new InterceptMethodCalls(hostMethodFilter, methodCallFilter); target.Accept(new ImplementModifiableType(typeFilter)); target.WeaveWith(rewriter, hostMethodFilter); }
/// <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); }
/// <summary> /// Modifies the current <paramref name="target"/> to support third-party method call interception. /// </summary> /// <param name="target">The target object.</param> /// <param name="typeFilter">The filter that will determine the target types that will be modified.</param> /// <param name="hostMethodFilter">The filter that will determine the methods that will be modified on the target type.</param> /// <param name="methodCallFilter">The filter that will determine which third-party methods will be intercepted on the target type.</param> public static void InterceptMethodCalls(this IReflectionVisitable target, Func<TypeReference, bool> typeFilter, Func<MethodReference, bool> hostMethodFilter, Func<MethodReference, bool> methodCallFilter) { var rewriter = new InterceptMethodCalls(hostMethodFilter, methodCallFilter); target.Accept(new ImplementModifiableType(typeFilter)); target.WeaveWith(rewriter, hostMethodFilter); }