/// <summary> /// Modifies the <paramref name="target"/> to support intercepting calls to the 'new' operator. /// </summary> /// <param name="target">The item to be modified.</param> /// <param name="newInstanceFilter">The filter that will determine which constructor calls should be intercepted.</param> /// <param name="methodFilter">The filter that will determine which host methods should be modified to support new instance interception.</param> public static void InterceptNewInstances(this IReflectionVisitable target, INewInstanceFilter newInstanceFilter, IMethodFilter methodFilter) { var redirector = new RedirectNewInstancesToActivator(newInstanceFilter); target.InterceptNewInstancesWith(redirector, methodFilter.ShouldWeave); }
/// <summary> /// Modifies the <paramref name="target"/> to support intercepting calls to the 'new' operator. /// </summary> /// <param name="target">The item to be modified.</param> /// <param name="constructorFilter">The functor that determines which type instantiations should be intercepted.</param> /// <param name="methodFilter">The filter that determines which host methods will be modified</param> /// <remarks> /// The type filter determines which concrete types and constructors should be intercepted at runtime. /// For example, the following functor code intercepts types named "Foo": /// <code> /// Func<MethodReference, TypeReference, bool> filter = /// (constructor, concreteType, hostMethod) => concreteType.Name == "Foo"; /// </code> /// </remarks> public static void InterceptNewInstances(this IReflectionVisitable target, Func <MethodReference, TypeReference, bool> constructorFilter, Func <MethodReference, bool> methodFilter) { Func <MethodReference, TypeReference, MethodReference, bool> filter = (ctor, declaringType, declaringMethod) => constructorFilter(ctor, declaringType) && methodFilter(declaringMethod); var redirector = new RedirectNewInstancesToActivator(filter); target.InterceptNewInstancesWith(redirector, methodFilter); }