BsMonoField.h 2.5 KB

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