IUIFactoryAdaptor.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using ILRuntime.CLR.Method;
  3. using ILRuntime.Runtime.Enviorment;
  4. using ILRuntime.Runtime.Intepreter;
  5. namespace Model
  6. {
  7. [ILAdapter]
  8. public class IUIFactoryAdaptorClassInheritanceAdaptor : CrossBindingAdaptor
  9. {
  10. public override Type BaseCLRType
  11. {
  12. get
  13. {
  14. return typeof (IUIFactory);
  15. }
  16. }
  17. public override Type AdaptorType
  18. {
  19. get
  20. {
  21. return typeof (IUIFactoryAdaptor);
  22. }
  23. }
  24. public override object CreateCLRInstance(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance)
  25. {
  26. return new IUIFactoryAdaptor(appdomain, instance);
  27. }
  28. public class IUIFactoryAdaptor : IUIFactory, CrossBindingAdaptorType
  29. {
  30. private ILTypeInstance instance;
  31. private ILRuntime.Runtime.Enviorment.AppDomain appDomain;
  32. private IMethod mCreate;
  33. private readonly object[] param3 = new object[3];
  34. public IUIFactoryAdaptor()
  35. {
  36. }
  37. public IUIFactoryAdaptor(ILRuntime.Runtime.Enviorment.AppDomain appDomain, ILTypeInstance instance)
  38. {
  39. this.appDomain = appDomain;
  40. this.instance = instance;
  41. }
  42. public ILTypeInstance ILInstance
  43. {
  44. get
  45. {
  46. return instance;
  47. }
  48. }
  49. public UI Create(Scene scene, int type, UI parent)
  50. {
  51. if (this.mCreate == null)
  52. {
  53. this.mCreate = instance.Type.GetMethod("Create", 3);
  54. }
  55. this.param3[0] = scene;
  56. this.param3[1] = type;
  57. this.param3[2] = parent;
  58. UI ui = (UI)this.appDomain.Invoke(this.mCreate, instance, this.param3);
  59. return ui;
  60. }
  61. public override string ToString()
  62. {
  63. IMethod m = this.appDomain.ObjectType.GetMethod("ToString", 0);
  64. m = instance.Type.GetVirtualMethod(m);
  65. if (m == null || m is ILMethod)
  66. {
  67. return instance.ToString();
  68. }
  69. return instance.Type.FullName;
  70. }
  71. }
  72. }
  73. }