/// <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> /// 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 TypeDefinition target, INewObjectWeaver weaver, Func <MethodReference, bool> filter) { var interceptNewCalls = new InterceptNewCalls(weaver); var targetMethods = target.Methods.Where(m => filter(m)).ToArray(); foreach (var targetMethod in targetMethods) { interceptNewCalls.Weave(targetMethod); } }
/// <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 AssemblyDefinition target, INewObjectWeaver weaver, Func <MethodReference, bool> filter) { IMethodWeaver interceptNewCalls = new InterceptNewCalls(weaver); var module = target.MainModule; var targetMethods = module.Types.SelectMany(t => t.Methods).Where(m => filter(m)).ToArray(); foreach (var targetMethod in targetMethods) { interceptNewCalls.Weave(targetMethod); } }
/// <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); }