/// <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 methods in the given <paramref name="target"/> using the custom <see cref="INewObjectWeaver"/> instance. /// </summary> /// <param name="target">The host that contains the methods that will be modified.</param> /// <param name="weaver">The custom <see cref="INewObjectWeaver"/> that will replace all calls to the new operator with the custom code emitted by the given weaver.</param> /// <param name="filter">The method filter that will determine which methods should be modified.</param> public static void InterceptNewInstancesWith(this IReflectionVisitable target, INewObjectWeaver weaver, Func <MethodReference, bool> filter) { var interceptNewCalls = new InterceptNewCalls(weaver); target.WeaveWith(interceptNewCalls, filter); }
/// <summary> /// Adds field interception support to the target type. /// </summary> /// <param name="targetType">The type that will be modified.</param> /// <param name="methodFilter">The filter that determines which methods on the target type will be modified to support field interception.</param> /// <param name="fieldFilter">The filter that determines which fields should be intercepted.</param> public static void InterceptFields(this IReflectionVisitable targetType, Func <MethodReference, bool> methodFilter, Func <FieldReference, bool> fieldFilter) { var typeWeaver = new ImplementFieldInterceptionHostWeaver(t => true); var fieldWeaver = new InterceptFieldAccess(fieldFilter); targetType.WeaveWith(fieldWeaver, methodFilter); targetType.Accept(typeWeaver); }
/// <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); }
public static void InterceptMethodBody(this IReflectionVisitable target, Func <MethodReference, bool> methodFilter, Func <TypeReference, bool> typeFilter) { target.Accept(new ImplementModifiableType(typeFilter)); var interceptMethodBody = new InterceptMethodBody(methodFilter); target.WeaveWith(interceptMethodBody, methodFilter); }
public static void InterceptExceptions(this IReflectionVisitable visitable, Func <MethodReference, bool> methodFilter) { if (visitable == null) { throw new ArgumentNullException("visitable"); } var catchAllThrownExceptions = new CatchAllThrownExceptions(); visitable.WeaveWith(catchAllThrownExceptions, methodFilter); }