/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

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