Reflection.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 Il2CppArray;
  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. class LIBIL2CPP_CODEGEN_API Reflection
  38. {
  39. // exported
  40. public:
  41. static Il2CppReflectionAssembly* GetAssemblyObject(const Il2CppAssembly *assembly);
  42. static Il2CppReflectionAssemblyName* GetAssemblyNameObject(const Il2CppAssemblyName *assemblyName);
  43. static Il2CppReflectionField* GetFieldObject(Il2CppClass *klass, FieldInfo *field);
  44. static Il2CppReflectionProperty* GetPropertyObject(Il2CppClass *klass, const PropertyInfo *property);
  45. static Il2CppReflectionEvent* GetEventObject(Il2CppClass *klass, const EventInfo *event);
  46. static Il2CppReflectionMethod* GetMethodObject(const MethodInfo *method, Il2CppClass *refclass);
  47. static const MethodInfo* GetMethod(const Il2CppReflectionMethod* method);
  48. static Il2CppReflectionModule* GetModuleObject(const Il2CppImage *image);
  49. static Il2CppReflectionType* GetTypeObject(const Il2CppType *type);
  50. static Il2CppArray* GetParamObjects(const MethodInfo *method, Il2CppClass *refclass);
  51. static Il2CppArray* GetCustomAttrsInfo(Il2CppObject *obj, Il2CppClass* attributeClass);
  52. static metadata::CustomAttributeDataReader GetCustomAttrsDataReader(Il2CppObject *obj);
  53. static const MonoGenericParameterInfo* GetMonoGenericParameterInfo(Il2CppMetadataGenericParameterHandle param);
  54. static void SetMonoGenericParameterInfo(Il2CppMetadataGenericParameterHandle param, const MonoGenericParameterInfo *monoParam);
  55. static const Il2CppMonoAssemblyName* GetMonoAssemblyName(const Il2CppAssembly *assembly);
  56. static void SetMonoAssemblyName(const Il2CppAssembly *assembly, const Il2CppMonoAssemblyName *aname);
  57. static int GetMetadataToken(Il2CppObject* obj);
  58. static bool HasAttribute(Il2CppObject *obj, Il2CppClass *attributeClass);
  59. static bool HasAttribute(FieldInfo *field, Il2CppClass *attributeClass);
  60. static bool HasAttribute(const MethodInfo *method, Il2CppClass *attributeClass);
  61. static bool HasAttribute(Il2CppClass *klass, Il2CppClass *attributeClass);
  62. static bool HasAttribute(Il2CppMetadataCustomAttributeHandle handle, Il2CppClass *attributeClass);
  63. static bool IsType(Il2CppObject *obj);
  64. static bool IsField(Il2CppObject *obj);
  65. static bool IsAnyMethod(Il2CppObject *obj);
  66. static bool IsProperty(Il2CppObject *obj);
  67. static bool IsEvent(Il2CppObject *obj);
  68. static void ClearStatics();
  69. // internal
  70. public:
  71. static void Initialize();
  72. static Il2CppClass* TypeGetHandle(Il2CppReflectionType* ref);
  73. static Il2CppObject* GetDBNullObject();
  74. static Il2CppObject* GetCustomAttribute(Il2CppMetadataCustomAttributeHandle token, Il2CppClass* attributeClass);
  75. static Il2CppArray* ConstructCustomAttributes(Il2CppMetadataCustomAttributeHandle token);
  76. private:
  77. static bool HasAttribute(Il2CppReflectionParameter *parameter, Il2CppClass* attributeClass);
  78. static bool HasAttribute(const il2cpp::metadata::CustomAttributeDataReader& reader, Il2CppClass* attributeClass);
  79. static Il2CppArray* GetCustomAttrsInfo(const il2cpp::metadata::CustomAttributeDataReader& reader, Il2CppClass* attributeClass);
  80. };
  81. } /* namespace vm */
  82. } /* namespace il2cpp */