/src/LinFu.Proxy.Interfaces/CallAdapter.cs

http://github.com/philiplaureano/LinFu · C# · 48 lines · 20 code · 8 blank · 20 comment · 0 complexity · 80ce4b95f78a1e7adab9047f4809165f MD5 · raw file

  1. using LinFu.AOP.Interfaces;
  2. namespace LinFu.Proxy
  3. {
  4. /// <summary>
  5. /// Adapts an <see cref="IInvokeWrapper" /> instance to an
  6. /// <see cref="IInterceptor" /> instance.
  7. /// </summary>
  8. internal class CallAdapter : IInterceptor
  9. {
  10. private readonly IInvokeWrapper _wrapper;
  11. /// <summary>
  12. /// Initializes the CallAdapter class with the <paramref name="wrapper" /> instance.
  13. /// </summary>
  14. /// <param name="wrapper">
  15. /// The <see cref="IInvokeWrapper" /> instance that will be called every time the interceptor is
  16. /// invoked.
  17. /// </param>
  18. public CallAdapter(IInvokeWrapper wrapper)
  19. {
  20. _wrapper = wrapper;
  21. }
  22. /// <summary>
  23. /// Intercepts a method call and passes the <see cref="IInvocationInfo" /> arguments
  24. /// down to the <see cref="IInvokeWrapper" /> instance.
  25. /// </summary>
  26. /// <param name="info">The <see cref="IInvocationInfo" /> instance that describes the method currently being executed.</param>
  27. /// <returns>The return value of the target method.</returns>
  28. public object Intercept(IInvocationInfo info)
  29. {
  30. object result = null;
  31. // Signal the beginning of the method call
  32. _wrapper.BeforeInvoke(info);
  33. // Process the method call itself
  34. result = _wrapper.DoInvoke(info);
  35. // Postprocess the results
  36. _wrapper.AfterInvoke(info, result);
  37. return result;
  38. }
  39. }
  40. }