BsMonoField.h 2.7 KB

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