IDisposableAdapter.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using ILRuntime.CLR.Method;
  3. using ILRuntime.Runtime.Enviorment;
  4. using ILRuntime.Runtime.Intepreter;
  5. namespace ET
  6. {
  7. public class IDisposableAdapter : CrossBindingAdaptor
  8. {
  9. static CrossBindingMethodInfo mDispose_0 = new CrossBindingMethodInfo("Dispose");
  10. public override Type BaseCLRType
  11. {
  12. get
  13. {
  14. return typeof(System.IDisposable);
  15. }
  16. }
  17. public override Type AdaptorType
  18. {
  19. get
  20. {
  21. return typeof(Adapter);
  22. }
  23. }
  24. public override object CreateCLRInstance(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance)
  25. {
  26. return new Adapter(appdomain, instance);
  27. }
  28. public class Adapter : System.IDisposable, CrossBindingAdaptorType
  29. {
  30. ILTypeInstance instance;
  31. ILRuntime.Runtime.Enviorment.AppDomain appdomain;
  32. public Adapter()
  33. {
  34. }
  35. public Adapter(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance)
  36. {
  37. this.appdomain = appdomain;
  38. this.instance = instance;
  39. }
  40. public ILTypeInstance ILInstance { get { return instance; } }
  41. public void Dispose()
  42. {
  43. mDispose_0.Invoke(this.instance);
  44. }
  45. public override string ToString()
  46. {
  47. IMethod m = appdomain.ObjectType.GetMethod("ToString", 0);
  48. m = instance.Type.GetVirtualMethod(m);
  49. if (m == null || m is ILMethod)
  50. {
  51. return instance.ToString();
  52. }
  53. else
  54. return instance.Type.FullName;
  55. }
  56. }
  57. }
  58. }