PageRenderTime 75ms CodeModel.GetById 33ms app.highlight 2ms RepoModel.GetById 38ms app.codeStats 0ms

/src/LinFu.AOP/Extensions/MethodRewriterExtensions.cs

http://github.com/philiplaureano/LinFu
C# | 39 lines | 22 code | 2 blank | 15 comment | 0 complexity | 4930bfcc6de10c9435b4ac190304d476 MD5 | raw file
 1using System;
 2using LinFu.AOP.Cecil.Interfaces;
 3using LinFu.AOP.Interfaces;
 4using Mono.Cecil;
 5
 6namespace LinFu.AOP.Cecil.Extensions
 7{
 8    /// <summary>
 9    ///     A helper class that extends Cecil to support the <see cref="IMethodRewriter" /> interface.
10    /// </summary>
11    public static class MethodRewriterExtensions
12    {
13        /// <summary>
14        ///     Transforms the methods in the <paramref name="target" /> using the given method rewriter.
15        /// </summary>
16        /// <param name="target">The transformation target.</param>
17        /// <param name="rewriter">The method rewriter.</param>
18        /// <param name="filter">The method filter that determines which methods will be rewritten.</param>
19        public static void WeaveWith(this IReflectionStructureVisitable target, IMethodRewriter rewriter,
20            Func<MethodReference, bool> filter)
21        {
22            var weaver = new MethodWeaver(rewriter, filter);
23            target.Accept(weaver);
24        }
25
26        /// <summary>
27        ///     Transforms the methods in the <paramref name="target" /> using the given method rewriter.
28        /// </summary>
29        /// <param name="target">The transformation target.</param>
30        /// <param name="rewriter">The method rewriter.</param>
31        /// <param name="filter">The method filter that determines which methods will be rewritten.</param>
32        public static void WeaveWith(this IReflectionVisitable target, IMethodRewriter rewriter,
33            Func<MethodReference, bool> filter)
34        {
35            var weaver = new MethodWeaver(rewriter, filter);
36            target.Accept(weaver);
37        }
38    }
39}