Reflection.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #pragma once
  2. #include <vector>
  3. #include <stdint.h>
  4. #include "il2cpp-config.h"
  5. #include "il2cpp-metadata.h"
  6. #include "metadata/CustomAttributeDataReader.h"
  7. struct Il2CppString;
  8. struct Il2CppArray;
  9. struct Il2CppReflectionAssembly;
  10. struct Il2CppReflectionAssemblyName;
  11. struct Il2CppReflectionField;
  12. struct Il2CppReflectionMethod;
  13. struct Il2CppReflectionModule;
  14. struct Il2CppReflectionProperty;
  15. struct Il2CppReflectionEvent;
  16. struct Il2CppReflectionType;
  17. struct Il2CppReflectionParameter;
  18. struct Il2CppClass;
  19. struct FieldInfo;
  20. struct MethodInfo;
  21. struct PropertyInfo;
  22. struct EventInfo;
  23. struct Il2CppClass;
  24. struct CustomAttributesCache;
  25. struct CustomAttributeTypeCache;
  26. struct Il2CppAssembly;
  27. struct Il2CppAssemblyName;
  28. struct Il2CppImage;
  29. struct Il2CppType;
  30. struct Il2CppObject;
  31. struct MonoGenericParameterInfo;
  32. struct Il2CppMonoAssemblyName;
  33. namespace il2cpp
  34. {
  35. namespace vm
  36. {
  37. struct ReflectionObjInfo
  38. {
  39. const Il2CppImage* image;
  40. uint32_t token;
  41. };
  42. class LIBIL2CPP_CODEGEN_API Reflection
  43. {
  44. // exported
  45. public:
  46. static Il2CppReflectionAssembly* GetAssemblyObject(const Il2CppAssembly *assembly);
  47. static Il2CppReflectionAssemblyName* GetAssemblyNameObject(const Il2CppAssemblyName *assemblyName);
  48. static Il2CppReflectionField* GetFieldObject(Il2CppClass *klass, FieldInfo *field);
  49. static Il2CppReflectionProperty* GetPropertyObject(Il2CppClass *klass, const PropertyInfo *property);
  50. static Il2CppReflectionEvent* GetEventObject(Il2CppClass *klass, const EventInfo *event);
  51. static Il2CppReflectionMethod* GetMethodObject(const MethodInfo *method, Il2CppClass *refclass);
  52. static const MethodInfo* GetMethod(const Il2CppReflectionMethod* method);
  53. static Il2CppReflectionModule* GetModuleObject(const Il2CppImage *image);
  54. static Il2CppReflectionType* GetTypeObject(const Il2CppType *type);
  55. static Il2CppArray* GetParamObjects(const MethodInfo *method, Il2CppClass *refclass);
  56. static CustomAttributesCache* GetCustomAttrsInfo(Il2CppObject *obj);
  57. static metadata::CustomAttributeDataReader GetCustomAttrsDataReader(Il2CppObject *obj);
  58. static const MonoGenericParameterInfo* GetMonoGenericParameterInfo(Il2CppMetadataGenericParameterHandle param);
  59. static void SetMonoGenericParameterInfo(Il2CppMetadataGenericParameterHandle param, const MonoGenericParameterInfo *monoParam);
  60. static const Il2CppMonoAssemblyName* GetMonoAssemblyName(const Il2CppAssembly *assembly);
  61. static void SetMonoAssemblyName(const Il2CppAssembly *assembly, const Il2CppMonoAssemblyName *aname);
  62. static int GetMetadataToken(Il2CppObject* obj);
  63. static bool HasAttribute(Il2CppObject *obj, Il2CppClass *attribute);
  64. static bool HasAttribute(FieldInfo *field, Il2CppClass *attribute);
  65. static bool HasAttribute(const MethodInfo *method, Il2CppClass *attribute);
  66. static bool HasAttribute(Il2CppClass *klass, Il2CppClass *attribute);
  67. static bool IsType(Il2CppObject *obj);
  68. static bool IsField(Il2CppObject *obj);
  69. static bool IsAnyMethod(Il2CppObject *obj);
  70. static bool IsProperty(Il2CppObject *obj);
  71. static bool IsEvent(Il2CppObject *obj);
  72. static void ClearStatics();
  73. static ReflectionObjInfo GetImageOfReflectionObject(Il2CppObject* obj);
  74. // internal
  75. public:
  76. static void Initialize();
  77. static Il2CppClass* TypeGetHandle(Il2CppReflectionType* ref);
  78. static Il2CppObject* GetDBNullObject();
  79. static Il2CppObject* GetCustomAttribute(Il2CppMetadataCustomAttributeHandle token, Il2CppClass* attribute);
  80. static Il2CppArray* ConstructCustomAttributes(Il2CppMetadataCustomAttributeHandle token);
  81. static CustomAttributesCache* GetCustomAttributesCacheFor(Il2CppClass *klass);
  82. static CustomAttributesCache* GetCustomAttributesCacheFor(const MethodInfo *method);
  83. private:
  84. static bool HasAttribute(Il2CppReflectionParameter *parameter, Il2CppClass* attribute);
  85. static CustomAttributesCache* GetCustomAttributesCacheFor(const PropertyInfo *property);
  86. static CustomAttributesCache* GetCustomAttributesCacheFor(FieldInfo *field);
  87. static CustomAttributesCache* GetCustomAttributesCacheFor(const EventInfo *event);
  88. static CustomAttributesCache* GetCustomAttributesCacheFor(Il2CppReflectionParameter *param);
  89. static CustomAttributesCache* GetCustomAttributesCacheFor(const Il2CppAssembly *assembly);
  90. static std::tuple<void*, void*> GetCustomAttributesDataRangeFor(Il2CppClass *klass);
  91. static std::tuple<void*, void*> GetCustomAttributesDataRangeFor(const MethodInfo *method);
  92. static std::tuple<void*, void*> GetCustomAttributesDataRangeFor(const PropertyInfo *property);
  93. static std::tuple<void*, void*> GetCustomAttributesDataRangeFor(FieldInfo *field);
  94. static std::tuple<void*, void*> GetCustomAttributesDataRangeFor(const EventInfo *event);
  95. static std::tuple<void*, void*> GetCustomAttributesDataRangeFor(Il2CppReflectionParameter *param);
  96. static std::tuple<void*, void*> GetCustomAttributesDataRangeFor(const Il2CppAssembly *assembly);
  97. };
  98. } /* namespace vm */
  99. } /* namespace il2cpp */