ILMethod.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using ILRuntime.CLR.Method;
  3. using ILRuntime.Runtime.Intepreter;
  4. namespace Model
  5. {
  6. public class ILInstanceMethod : IInstanceMethod
  7. {
  8. private readonly ILRuntime.Runtime.Enviorment.AppDomain appDomain;
  9. private readonly ILTypeInstance instance;
  10. private readonly IMethod method;
  11. public ILInstanceMethod(Type type, string methodName)
  12. {
  13. this.Name = methodName;
  14. appDomain = Game.EntityEventManager.AppDomain;
  15. this.instance = this.appDomain.Instantiate(type.FullName);
  16. this.method = this.instance.Type.GetMethod(methodName);
  17. }
  18. public override void Run(params object[] param)
  19. {
  20. this.appDomain.Invoke(this.method, this.instance, param);
  21. }
  22. }
  23. public class ILCommonMethod : ICommonMethod
  24. {
  25. private readonly ILRuntime.Runtime.Enviorment.AppDomain appDomain;
  26. private readonly IMethod method;
  27. private readonly object[] param;
  28. public ILCommonMethod(IMethod method, int paramsCount)
  29. {
  30. this.param = new object[paramsCount + 1];
  31. this.Name = method.Name;
  32. appDomain = Game.EntityEventManager.AppDomain;
  33. this.method = method;
  34. }
  35. public override void Run(object instance, params object[] p)
  36. {
  37. if (this.method.IsStatic)
  38. {
  39. this.param[0] = instance;
  40. for (int i = 0; i < p.Length; ++i)
  41. {
  42. this.param[1 + i] = p[i];
  43. }
  44. this.appDomain.Invoke(this.method, null, this.param);
  45. return;
  46. }
  47. this.appDomain.Invoke(this.method, instance, p);
  48. }
  49. }
  50. }