IEventMethod.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using ILRuntime.CLR.Method;
  3. using ILRuntime.Runtime.Intepreter;
  4. namespace Model
  5. {
  6. public interface IEventMethod
  7. {
  8. void Run();
  9. void Run<A>(A a);
  10. void Run<A, B>(A a, B b);
  11. void Run<A, B, C>(A a, B b, C c);
  12. void Run<A, B, C, D>(A a, B b, C c, D d);
  13. }
  14. public class IEventMonoMethod : IEventMethod
  15. {
  16. private readonly object obj;
  17. public IEventMonoMethod(object obj)
  18. {
  19. this.obj = obj;
  20. }
  21. public void Run()
  22. {
  23. ((IEvent)obj).Run();
  24. }
  25. public void Run<A>(A a)
  26. {
  27. ((IEvent<A>)obj).Run(a);
  28. }
  29. public void Run<A, B>(A a, B b)
  30. {
  31. ((IEvent<A, B>)obj).Run(a, b);
  32. }
  33. public void Run<A, B, C>(A a, B b, C c)
  34. {
  35. ((IEvent<A, B, C>)obj).Run(a, b, c);
  36. }
  37. public void Run<A, B, C, D>(A a, B b, C c, D d)
  38. {
  39. ((IEvent<A, B, C, D>)obj).Run(a, b, c, d);
  40. }
  41. }
  42. public class IEventILMethod : IEventMethod
  43. {
  44. private readonly ILRuntime.Runtime.Enviorment.AppDomain appDomain;
  45. private readonly ILTypeInstance instance;
  46. private readonly IMethod method;
  47. private readonly object[] param;
  48. public IEventILMethod(Type type, string methodName)
  49. {
  50. appDomain = Init.Instance.AppDomain;
  51. this.instance = this.appDomain.Instantiate(type.FullName);
  52. this.method = this.instance.Type.GetMethod(methodName);
  53. int n = this.method.ParameterCount;
  54. this.param = new object[n];
  55. }
  56. public void Run()
  57. {
  58. this.appDomain.Invoke(this.method, this.instance, param);
  59. }
  60. public void Run<A>(A a)
  61. {
  62. this.param[0] = a;
  63. this.appDomain.Invoke(this.method, this.instance, param);
  64. }
  65. public void Run<A, B>(A a, B b)
  66. {
  67. this.param[0] = a;
  68. this.param[1] = b;
  69. this.appDomain.Invoke(this.method, this.instance, param);
  70. }
  71. public void Run<A, B, C>(A a, B b, C c)
  72. {
  73. this.param[0] = a;
  74. this.param[1] = b;
  75. this.param[2] = c;
  76. this.appDomain.Invoke(this.method, this.instance, param);
  77. }
  78. public void Run<A, B, C, D>(A a, B b, C c, D d)
  79. {
  80. this.param[0] = a;
  81. this.param[1] = b;
  82. this.param[2] = c;
  83. this.param[3] = d;
  84. this.appDomain.Invoke(this.method, this.instance, param);
  85. }
  86. }
  87. }