MethodReference.cs 825 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. namespace SRF.Helpers
  3. {
  4. using System.Reflection;
  5. public sealed class MethodReference
  6. {
  7. private readonly Func<object[], object> _method;
  8. public MethodReference(object target, MethodInfo method)
  9. {
  10. SRDebugUtil.AssertNotNull(target);
  11. _method = o => method.Invoke(target, o);
  12. }
  13. public MethodReference(Func<object[], object> method)
  14. {
  15. _method = method;
  16. }
  17. public object Invoke(object[] parameters)
  18. {
  19. return _method.Invoke(parameters);
  20. }
  21. public static implicit operator MethodReference(Action action)
  22. {
  23. return new MethodReference(args =>
  24. {
  25. action();
  26. return null;
  27. });
  28. }
  29. }
  30. }