BsMonoProperty.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. /**
  11. * Encapsulates information about a single Mono (managed) property belonging to some managed class. This object
  12. * also allows you to set or retrieve values to/from specific instances containing the property.
  13. */
  14. class BS_MONO_EXPORT MonoProperty
  15. {
  16. public:
  17. /** Returns the name of the property. */
  18. const String& getName() const { return mName; }
  19. /**
  20. * Returns a boxed value contained in the property in the specified instance.
  21. *
  22. * @param[in] instance Object instance to access the property on. Can be null for static properties.
  23. * @return A boxed value of the property.
  24. */
  25. MonoObject* get(MonoObject* instance) const;
  26. /**
  27. * Sets a value of the property in the specified instance.
  28. *
  29. * @param[in] instance Object instance to access the property on. Can be null for static properties.
  30. * @param[in] value Value to set on the property. For value type it should be a pointer to the value and for
  31. * reference type it should be a pointer to MonoObject.
  32. */
  33. void set(MonoObject* instance, void* value) const;
  34. /**
  35. * Returns a boxed value contained in the property in the specified instance. Used for properties with indexers.
  36. *
  37. * @param[in] instance Object instance to access the property on. Can be null for static properties.
  38. * @param[in] index Index of the value to retrieve.
  39. * @return A boxed value of the property.
  40. */
  41. MonoObject* getIndexed(MonoObject* instance, UINT32 index) const;
  42. /**
  43. * Sets a value of the property in the specified instance. Used for properties with indexers.
  44. *
  45. * @param[in] instance Object instance to access the property on. Can be null for static properties.
  46. * @param[in] index Index of the value to set.
  47. * @param[in] value Value to set on the property. For value type it should be a pointer to the value and for
  48. * reference type it should be a pointer to MonoObject.
  49. */
  50. void setIndexed(MonoObject* instance, UINT32 index, void* value) const;
  51. /** Checks does the property contains indexed data, or just a single value. */
  52. bool isIndexed() const;
  53. /** Returns the data type the property holds. */
  54. MonoClass* getReturnType() const;
  55. /** Checks if property has an attribute of the specified type. */
  56. bool hasAttribute(MonoClass* monoClass);
  57. /**
  58. * Returns an instance of an attribute of the specified type. Returns null if the property doesn't have such an
  59. * attribute.
  60. */
  61. MonoObject* getAttribute(MonoClass* monoClass);
  62. /**
  63. * Returns property visibility in the class. If getter/setter methods have different visibility, the more
  64. * restrictive one is returned.
  65. */
  66. MonoMemberVisibility getVisibility();
  67. private:
  68. friend class MonoClass;
  69. MonoProperty(::MonoProperty* monoProp);
  70. /**
  71. * Some property data is not initialized by default on creation (with the assumption it will never be accessed).
  72. * This method will initialize that data.
  73. */
  74. void initializeDeferred() const;
  75. String mName;
  76. ::MonoProperty* mProperty;
  77. ::MonoMethod* mGetMethod;
  78. ::MonoMethod* mSetMethod;
  79. mutable MonoClass* mReturnType;
  80. mutable bool mIsIndexed;
  81. mutable bool mIsFullyInitialized;
  82. };
  83. /** @} */
  84. }