BsMonoField.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include "BsMonoPrerequisites.h"
  3. #include <mono/jit/jit.h>
  4. #include <mono/metadata/class.h>
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Returns the level of field visibility in the class.
  9. */
  10. enum class MonoFieldVisibility
  11. {
  12. Private,
  13. ProtectedInternal,
  14. Internal,
  15. Protected,
  16. Public
  17. };
  18. /**
  19. * @brief Encapsulates information about a single Mono (i.e. managed) field
  20. * belonging to some managed class. This object also allows you to set
  21. * or retrieve values to/from specific instances containing the field.
  22. */
  23. class BS_MONO_EXPORT MonoField
  24. {
  25. public:
  26. /**
  27. * @brief Returns the name of the field.
  28. */
  29. const String& getName() const { return mName; }
  30. /**
  31. * @brief Returns the class representing the type of data the field holds.
  32. */
  33. MonoClass* getType();
  34. /**
  35. * @brief Retrieves value currently set in the field on the specified object instance.
  36. * If field is static object instance can be null.
  37. *
  38. * @note Value will be a pointer to raw data type for value types (e.g. int, float), and a MonoObject*
  39. * for reference types.
  40. */
  41. void getValue(MonoObject* instance, void* outValue);
  42. /**
  43. * @brief Retrieves value currently set in the field on the specified object instance.
  44. * If field is static object instance can be null. If returned value is a value
  45. * type it will be boxed.
  46. */
  47. MonoObject* getValueBoxed(MonoObject* instance);
  48. /**
  49. * @brief Sets a value for the field on the specified object instance.
  50. * If field is static object instance can be null.
  51. *
  52. * @note Value should be a pointer to raw data type for value types (e.g. int, float), and a MonoObject*
  53. * for reference types.
  54. */
  55. void setValue(MonoObject* instance, void* value);
  56. /**
  57. * @brief Checks if field has an attribute of the specified type.
  58. */
  59. bool hasAttribute(MonoClass* monoClass);
  60. /**
  61. * @brief Returns an instance of an attribute of the specified type. Returns null
  62. * if the field doesn't have such an attribute.
  63. */
  64. MonoObject* getAttribute(MonoClass* monoClass);
  65. /**
  66. * @brief Returns field visibility in the class.
  67. */
  68. MonoFieldVisibility getVisibility();
  69. /**
  70. * @brief Query if the field is static.
  71. */
  72. bool isStatic();
  73. private:
  74. friend class MonoClass;
  75. MonoField(MonoClassField* field);
  76. String mName;
  77. MonoClassField* mField;
  78. MonoClass* mFieldType;
  79. };
  80. }