BsMonoField.h 2.6 KB

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