コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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 AssemblyDefinition target,
                                                 INewInstanceFilter newInstanceFilter, IMethodFilter methodFilter)
        {
            var redirector = new RedirectNewInstancesToActivator(newInstanceFilter);

            target.InterceptNewInstancesWith(redirector, methodFilter.ShouldWeave);
        }
コード例 #3
0
        /// <summary>
        /// Modifies a <paramref name="target"/> assembly to support intercepting calls to the 'new' operator.
        /// </summary>
        /// <param name="target">The assembly 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&lt;MethodReference, TypeReference, bool&gt; filter = 
        ///     (constructor, concreteType, hostMethod) => concreteType.Name == "Foo";
        /// </code>
        /// </remarks>
        public static void InterceptNewInstances(this IReflectionStructureVisitable 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);
        }
コード例 #4
0
        /// <summary>
        /// Modifies a <paramref name="target"/> assembly to support intercepting calls to the 'new' operator.
        /// </summary>
        /// <param name="target">The assembly 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&lt;MethodReference, TypeReference, bool&gt; filter =
        ///     (constructor, concreteType, hostMethod) => concreteType.Name == "Foo";
        /// </code>
        /// </remarks>
        public static void InterceptNewInstances(this IReflectionStructureVisitable 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);
        }
コード例 #5
0
        /// <summary>
        ///     Modifies a <paramref name="target" /> to support intercepting calls to the 'new' operator.
        /// </summary>
        /// <param name="target">The assembly to be modified.</param>
        /// <param name="typeFilter">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 the concrete types that should be intercepted at runtime.
        ///     For example, the following functor code intercepts types named "Foo":
        ///     <code>
        ///     Func&lt;TypeReference, bool&gt; filter =
        ///     concreteType => concreteType.Name == "Foo";
        /// </code>
        /// </remarks>
        public static void InterceptNewInstances(this TypeDefinition target, Func <TypeReference, bool> typeFilter,
                                                 Func <MethodReference, bool> methodFilter)
        {
            Func <MethodReference, TypeReference, bool> constructorFilter =
                (constructor, declaringType) => methodFilter(constructor) && typeFilter(declaringType);

            Func <MethodReference, TypeReference, MethodReference, bool> filter =
                (ctor, declaringType, declaringMethod) =>
                constructorFilter(ctor, declaringType) && methodFilter(declaringMethod);

            var redirector = new RedirectNewInstancesToActivator(filter);

            target.InterceptNewInstancesWith(redirector, methodFilter);
        }
コード例 #6
0
 /// <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);
 }