// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Collections/Array.h" #include "MTypes.h" /// /// Encapsulates information about a single Mono (managed) fields belonging to some managed class. This object also allows you to access the field data of an object instance. /// class MField { friend MClass; protected: #if USE_MONO MonoClassField* _monoField; MonoType* _monoType; #endif MClass* _parentClass; MString _name; MVisibility _visibility; Array _attributes; int32 _hasCachedAttributes : 1; int32 _isStatic : 1; public: #if USE_MONO explicit MField(MonoClassField* monoField, const char* name, MClass* parentClass); #endif public: /// /// Gets field name. /// /// The field name. FORCE_INLINE const MString& GetName() const { return _name; } /// /// Returns the parent class that this method is contained with. /// /// The parent class. FORCE_INLINE MClass* GetParentClass() const { return _parentClass; } /// /// Gets field type class. /// /// The field type. MType GetType() const; /// /// Gets the field offset (in bytes) from the start of the parent object. /// /// The field offset in bytes. int32 GetOffset() const; /// /// Gets field visibility in the class. /// /// The field visibility. FORCE_INLINE MVisibility GetVisibility() const { return _visibility; } /// /// Returns true if field is static. /// /// True if is static, otherwise false. FORCE_INLINE bool IsStatic() const { return _isStatic != 0; } #if USE_MONO /// /// Gets mono field handle. /// /// The Mono field object. FORCE_INLINE MonoClassField* GetNative() const { return _monoField; } #endif public: /// /// Retrieves value currently set in the field on the specified object instance. If field is static object instance can be null. /// /// /// Value will be a pointer to raw data type for value types (for example int, float), and a MonoObject* for reference types. /// /// The object of given type to get value from. /// The return value of undefined type. void GetValue(MonoObject* instance, void* result) const; /// /// Retrieves value currently set in the field on the specified object instance. If field is static object instance can be null. If returned value is a value type it will be boxed. /// /// The object of given type to get value from. /// The boxed value object. MonoObject* GetValueBoxed(MonoObject* instance) const; /// /// Sets a value for the field on the specified object instance. If field is static object instance can be null. /// /// /// Value should be a pointer to raw data type for value types (for example int, float), and a MonoObject* for reference types. /// /// The object of given type to set value to. /// Th value of undefined type. void SetValue(MonoObject* instance, void* value) const; public: /// /// Checks if field has an attribute of the specified type. /// /// The attribute class to check. /// True if has attribute of that class type, otherwise false. bool HasAttribute(MClass* monoClass) const; /// /// Checks if field has an attribute of any type. /// /// True if has any custom attribute, otherwise false. bool HasAttribute() const; /// /// Returns an instance of an attribute of the specified type. Returns null if the field doesn't have such an attribute. /// /// The attribute class to take. /// The attribute object. MonoObject* GetAttribute(MClass* monoClass) const; /// /// Returns an instance of all attributes connected with given field. Returns null if the field doesn't have any attributes. /// /// The array of attribute objects. const Array& GetAttributes(); };