CLRCrossBindingAdaptors.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ILRuntime.CLR.Method;
  6. using ILRuntime.Runtime.Enviorment;
  7. using ILRuntime.Runtime.Intepreter;
  8. namespace ILRuntime.Runtime.Adapters
  9. {
  10. public class AttributeAdapter : CrossBindingAdaptor
  11. {
  12. public override Type AdaptorType
  13. {
  14. get
  15. {
  16. return typeof(Adapter);
  17. }
  18. }
  19. public override Type BaseCLRType
  20. {
  21. get
  22. {
  23. return typeof(Attribute);
  24. }
  25. }
  26. public override object CreateCLRInstance(Enviorment.AppDomain appdomain, ILTypeInstance instance)
  27. {
  28. return new Adapter(appdomain, instance);
  29. }
  30. public class Adapter : Attribute, CrossBindingAdaptorType
  31. {
  32. ILTypeInstance instance;
  33. ILRuntime.Runtime.Enviorment.AppDomain appdomain;
  34. bool isToStringGot;
  35. IMethod toString;
  36. public Adapter(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance)
  37. {
  38. this.appdomain = appdomain;
  39. this.instance = instance;
  40. }
  41. public ILTypeInstance ILInstance
  42. {
  43. get
  44. {
  45. return instance;
  46. }
  47. }
  48. public override string ToString()
  49. {
  50. if (!isToStringGot)
  51. {
  52. isToStringGot = true;
  53. IMethod m = appdomain.ObjectType.GetMethod("ToString", 0);
  54. toString = instance.Type.GetVirtualMethod(m);
  55. }
  56. if (toString == null || toString is ILMethod)
  57. {
  58. return instance.ToString();
  59. }
  60. else
  61. return instance.Type.FullName;
  62. }
  63. }
  64. }
  65. }