/src/LinFu.Proxy.Interfaces/FunctorAsInterceptor.cs

http://github.com/philiplaureano/LinFu · C# · 37 lines · 19 code · 5 blank · 13 comment · 2 complexity · 8964008bedefcbdaab5442aba49f1b6f MD5 · raw file

  1. using System;
  2. using LinFu.AOP.Interfaces;
  3. namespace LinFu.Proxy.Interfaces
  4. {
  5. /// <summary>
  6. /// A class that converts a functor into an <see cref="IInterceptor" /> instance.
  7. /// </summary>
  8. public class FunctorAsInterceptor : IInterceptor
  9. {
  10. private readonly Func<IInvocationInfo, object> _doIntercept;
  11. /// <summary>
  12. /// Initializes the class with the given <paramref name="intercept">functor</paramref>.
  13. /// </summary>
  14. /// <param name="intercept">The functor that will be invoked every time a method is called on the proxy type.</param>
  15. public FunctorAsInterceptor(Func<IInvocationInfo, object> intercept)
  16. {
  17. _doIntercept = intercept;
  18. }
  19. /// <summary>
  20. /// A method that redirects the method calls to
  21. /// the functor instance.
  22. /// </summary>
  23. /// <param name="info">The <see cref="IInvocationInfo" /> instance that describes the context of the method call.</param>
  24. /// <returns>The return value from the target method.</returns>
  25. public object Intercept(IInvocationInfo info)
  26. {
  27. if (_doIntercept == null)
  28. throw new NotImplementedException();
  29. return _doIntercept(info);
  30. }
  31. }
  32. }