/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
- using System;
- using LinFu.AOP.Cecil.Interfaces;
- using LinFu.AOP.Interfaces;
- using Mono.Cecil;
- namespace LinFu.AOP.Cecil.Extensions
- {
- /// <summary>
- /// A helper class that extends Cecil to support the <see cref="IMethodRewriter" /> interface.
- /// </summary>
- public static class MethodRewriterExtensions
- {
- /// <summary>
- /// Transforms the methods in the <paramref name="target" /> using the given method rewriter.
- /// </summary>
- /// <param name="target">The transformation target.</param>
- /// <param name="rewriter">The method rewriter.</param>
- /// <param name="filter">The method filter that determines which methods will be rewritten.</param>
- public static void WeaveWith(this IReflectionStructureVisitable target, IMethodRewriter rewriter,
- Func<MethodReference, bool> filter)
- {
- var weaver = new MethodWeaver(rewriter, filter);
- target.Accept(weaver);
- }
- /// <summary>
- /// Transforms the methods in the <paramref name="target" /> using the given method rewriter.
- /// </summary>
- /// <param name="target">The transformation target.</param>
- /// <param name="rewriter">The method rewriter.</param>
- /// <param name="filter">The method filter that determines which methods will be rewritten.</param>
- public static void WeaveWith(this IReflectionVisitable target, IMethodRewriter rewriter,
- Func<MethodReference, bool> filter)
- {
- var weaver = new MethodWeaver(rewriter, filter);
- target.Accept(weaver);
- }
- }
- }