// 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 property belonging to some managed class.
/// This object also allows you to set or retrieve values to or from specific instances containing the property.
///
class FLAXENGINE_API MProperty
{
friend MClass;
protected:
#if USE_MONO
MonoProperty* _monoProperty;
#endif
MMethod* _getMethod;
MMethod* _setMethod;
MClass* _parentClass;
MString _name;
Array _attributes;
int32 _hasCachedAttributes : 1;
int32 _hasSetMethod : 1;
int32 _hasGetMethod : 1;
public:
#if USE_MONO
explicit MProperty(MonoProperty* monoProperty, const char* name, MClass* parentClass);
#endif
///
/// Finalizes an instance of the class.
///
~MProperty();
public:
///
/// Gets the property name.
///
/// The property 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 property type class.
///
/// The property type.
MType GetType();
///
/// Gets property get method.
///
/// The getter method.
MMethod* GetGetMethod();
///
/// Gets property set method.
///
/// The setter method.
MMethod* GetSetMethod();
///
/// Gets property visibility in the class.
///
/// The property visibility.
MVisibility GetVisibility();
///
/// Returns true if property is static.
///
/// True if is static, otherwise false.
bool IsStatic();
public:
///
/// Retrieves value currently set in the property on the specified object instance. If property 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.
/// An optional pointer to the exception value to store exception object reference.
/// The returned boxed value object.
MonoObject* GetValue(MonoObject* instance, MonoObject** exception);
///
/// Sets a value for the property on the specified object instance. If property 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.
///
/// Object of given type to set value to.
/// An optional pointer to the exception value to store exception object reference.
/// The value to set of undefined type.
void SetValue(MonoObject* instance, void* value, MonoObject** exception);
public:
///
/// Checks if property 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 property 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 property 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 property. Returns null if the property doesn't have any attributes.
///
/// The array of attribute objects.
const Array& GetAttributes();
};