/src/LinFu.AOP.Interfaces/CompositeAroundInvoke.cs

http://github.com/philiplaureano/LinFu · C# · 36 lines · 28 code · 7 blank · 1 comment · 4 complexity · fe422c49c7630d5604215b0fe6943334 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. namespace LinFu.AOP.Interfaces
  4. {
  5. internal class CompositeAroundInvoke : IAroundInvoke
  6. {
  7. private readonly IList<IAroundInvoke> _aroundInvokeList = new List<IAroundInvoke>();
  8. public CompositeAroundInvoke(IEnumerable<IAroundInvoke> aroundInvokeList)
  9. {
  10. if (aroundInvokeList == null)
  11. throw new ArgumentNullException("aroundInvokeList");
  12. // Filter out the null values
  13. foreach (var current in aroundInvokeList)
  14. {
  15. if (current == null)
  16. continue;
  17. _aroundInvokeList.Add(current);
  18. }
  19. }
  20. public void AfterInvoke(IInvocationInfo context, object returnValue)
  21. {
  22. foreach (var invoke in _aroundInvokeList) invoke.AfterInvoke(context, returnValue);
  23. }
  24. public void BeforeInvoke(IInvocationInfo context)
  25. {
  26. foreach (var invoke in _aroundInvokeList) invoke.BeforeInvoke(context);
  27. }
  28. }
  29. }