// Copyright (c) 2012-2024 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; #elif USE_NETCORE void* _handle; #endif mutable MMethod* _addMethod; mutable MMethod* _removeMethod; MClass* _parentClass; StringAnsi _name; mutable int32 _hasCachedAttributes : 1; mutable int32 _hasAddMonoMethod : 1; mutable int32 _hasRemoveMonoMethod : 1; mutable Array _attributes; public: #if USE_MONO explicit MEvent(MonoEvent* monoEvent, const char* name, MClass* parentClass); #elif USE_NETCORE MEvent(MClass* parentClass, void* handle, const char* name); #endif public: /// /// Gets the event name. /// FORCE_INLINE const StringAnsi& 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() const; /// /// Gets the event add method. /// MMethod* GetAddMethod() const; /// /// Gets the event remove method. /// MMethod* GetRemoveMethod() const; /// /// Gets event visibility in the class. /// FORCE_INLINE MVisibility GetVisibility() const { return GetAddMethod()->GetVisibility(); } /// /// Returns true if event is static. /// FORCE_INLINE bool IsStatic() const { 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(const MClass* klass) 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(const MClass* klass) 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() const; };