// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#include "MMethod.h"
///
/// Encapsulates information about a single Mono (managed) event belonging to some managed class. This object also allows you to invoke this event or register other methods to it.
///
class FLAXENGINE_API MEvent
{
friend MClass;
protected:
#if USE_MONO
MonoEvent* _monoEvent;
#endif
MMethod* _addMethod;
MMethod* _removeMethod;
MClass* _parentClass;
MString _name;
int32 _hasCachedAttributes : 1;
int32 _hasAddMonoMethod : 1;
int32 _hasRemoveMonoMethod : 1;
Array _attributes;
public:
#if USE_MONO
explicit MEvent(MonoEvent* monoEvent, const char* name, MClass* parentClass);
#endif
public:
///
/// Gets the event name.
///
FORCE_INLINE const MString& GetName() const
{
return _name;
}
///
/// Returns the parent class that this method is contained with.
///
FORCE_INLINE MClass* GetParentClass() const
{
return _parentClass;
}
///
/// Gets the event type class.
///
MType GetType();
///
/// Gets the event add method.
///
MMethod* GetAddMethod();
///
/// Gets the event remove method.
///
MMethod* GetRemoveMethod();
///
/// Gets event visibility in the class.
///
FORCE_INLINE MVisibility GetVisibility()
{
return GetAddMethod()->GetVisibility();
}
///
/// Returns true if event is static.
///
FORCE_INLINE bool IsStatic()
{
return GetAddMethod()->IsStatic();
}
#if USE_MONO
///
/// Gets the Mono event handle.
///
FORCE_INLINE MonoEvent* GetNative() const
{
return _monoEvent;
}
#endif
public:
///
/// Checks if event 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 event 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 event doesn't have such an attribute.
///
/// The attribute class to take.
/// The attribute object.
MObject* GetAttribute(MClass* monoClass) const;
///
/// Returns an instance of all attributes connected with given event. Returns null if the event doesn't have any attributes.
///
/// The array of attribute objects.
const Array& GetAttributes();
};