LitJson_JsonMapper_Binding.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Runtime.InteropServices;
  6. using ILRuntime.CLR.TypeSystem;
  7. using ILRuntime.CLR.Method;
  8. using ILRuntime.Runtime.Enviorment;
  9. using ILRuntime.Runtime.Intepreter;
  10. using ILRuntime.Runtime.Stack;
  11. using ILRuntime.Reflection;
  12. using ILRuntime.CLR.Utils;
  13. namespace ILRuntime.Runtime.Generated
  14. {
  15. unsafe class LitJson_JsonMapper_Binding
  16. {
  17. public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
  18. {
  19. BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
  20. MethodBase method;
  21. Type[] args;
  22. Type type = typeof(LitJson.JsonMapper);
  23. Dictionary<string, List<MethodInfo>> genericMethods = new Dictionary<string, List<MethodInfo>>();
  24. List<MethodInfo> lst = null;
  25. foreach(var m in type.GetMethods())
  26. {
  27. if(m.IsGenericMethodDefinition)
  28. {
  29. if (!genericMethods.TryGetValue(m.Name, out lst))
  30. {
  31. lst = new List<MethodInfo>();
  32. genericMethods[m.Name] = lst;
  33. }
  34. lst.Add(m);
  35. }
  36. }
  37. args = new Type[]{typeof(ILRuntime.Runtime.Intepreter.ILTypeInstance)};
  38. if (genericMethods.TryGetValue("ToObject", out lst))
  39. {
  40. foreach(var m in lst)
  41. {
  42. if(m.MatchGenericParameters(args, typeof(ILRuntime.Runtime.Intepreter.ILTypeInstance), typeof(System.String)))
  43. {
  44. method = m.MakeGenericMethod(args);
  45. app.RegisterCLRMethodRedirection(method, ToObject_0);
  46. break;
  47. }
  48. }
  49. }
  50. args = new Type[]{typeof(System.Object)};
  51. method = type.GetMethod("ToJson", flag, null, args, null);
  52. app.RegisterCLRMethodRedirection(method, ToJson_1);
  53. }
  54. static StackObject* ToObject_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
  55. {
  56. ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
  57. StackObject* ptr_of_this_method;
  58. StackObject* __ret = ILIntepreter.Minus(__esp, 1);
  59. ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
  60. System.String @json = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
  61. __intp.Free(ptr_of_this_method);
  62. var result_of_this_method = LitJson.JsonMapper.ToObject<ILRuntime.Runtime.Intepreter.ILTypeInstance>(@json);
  63. return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
  64. }
  65. static StackObject* ToJson_1(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
  66. {
  67. ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
  68. StackObject* ptr_of_this_method;
  69. StackObject* __ret = ILIntepreter.Minus(__esp, 1);
  70. ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
  71. System.Object @obj = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
  72. __intp.Free(ptr_of_this_method);
  73. var result_of_this_method = LitJson.JsonMapper.ToJson(@obj);
  74. return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
  75. }
  76. }
  77. }