Refactor CoreCLR runtime into explicit dotnet api instead of mocking mono api
Required by platforms that will use mono under the hood for .Net 7 New `USE_CSHARP` define for C# ability Engine doesn't use `mono_*` apis directly but via MCore/MClass/MMethod/ apis
This commit is contained in:
@@ -10,44 +10,49 @@
|
||||
/// </summary>
|
||||
class FLAXENGINE_API MClass
|
||||
{
|
||||
friend MCore;
|
||||
private:
|
||||
|
||||
#if USE_MONO
|
||||
MonoClass* _monoClass;
|
||||
mutable void* _attrInfo = nullptr;
|
||||
#elif USE_NETCORE
|
||||
void* _handle;
|
||||
StringAnsi _name;
|
||||
StringAnsi _namespace_;
|
||||
uint32 _types = 0;
|
||||
mutable uint32 _size = 0;
|
||||
#endif
|
||||
const MAssembly* _assembly;
|
||||
|
||||
MString _fullname;
|
||||
StringAnsi _fullname;
|
||||
|
||||
Array<MMethod*> _methods;
|
||||
Array<MField*> _fields;
|
||||
Array<MProperty*> _properties;
|
||||
Array<MObject*> _attributes;
|
||||
Array<MEvent*> _events;
|
||||
mutable Array<MMethod*> _methods;
|
||||
mutable Array<MField*> _fields;
|
||||
mutable Array<MProperty*> _properties;
|
||||
mutable Array<MObject*> _attributes;
|
||||
mutable Array<MEvent*> _events;
|
||||
mutable Array<MClass*> _interfaces;
|
||||
|
||||
MVisibility _visibility;
|
||||
|
||||
int32 _hasCachedProperties : 1;
|
||||
int32 _hasCachedFields : 1;
|
||||
int32 _hasCachedMethods : 1;
|
||||
int32 _hasCachedAttributes : 1;
|
||||
int32 _hasCachedEvents : 1;
|
||||
mutable int32 _hasCachedProperties : 1;
|
||||
mutable int32 _hasCachedFields : 1;
|
||||
mutable int32 _hasCachedMethods : 1;
|
||||
mutable int32 _hasCachedAttributes : 1;
|
||||
mutable int32 _hasCachedEvents : 1;
|
||||
mutable int32 _hasCachedInterfaces : 1;
|
||||
int32 _isStatic : 1;
|
||||
int32 _isSealed : 1;
|
||||
int32 _isAbstract : 1;
|
||||
int32 _isInterface : 1;
|
||||
int32 _isValueType : 1;
|
||||
int32 _isEnum : 1;
|
||||
|
||||
public:
|
||||
|
||||
#if USE_MONO
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MClass"/> class.
|
||||
/// </summary>
|
||||
/// <param name="parentAssembly">The parent assembly.</param>
|
||||
/// <param name="monoClass">The Mono class.</param>
|
||||
/// <param name="fullname">The fullname.</param>
|
||||
MClass(const MAssembly* parentAssembly, MonoClass* monoClass, const MString& fullname);
|
||||
MClass(const MAssembly* parentAssembly, MonoClass* monoClass, const StringAnsi& fullname);
|
||||
#elif USE_NETCORE
|
||||
MClass(const MAssembly* parentAssembly, void* handle, const char* name, const char* fullname, const char* namespace_, MTypeAttributes typeAttributes);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
@@ -56,7 +61,6 @@ public:
|
||||
~MClass();
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent assembly.
|
||||
/// </summary>
|
||||
@@ -68,11 +72,21 @@ public:
|
||||
/// <summary>
|
||||
/// Gets the full name of the class (namespace and typename).
|
||||
/// </summary>
|
||||
FORCE_INLINE const MString& GetFullName() const
|
||||
FORCE_INLINE const StringAnsi& GetFullName() const
|
||||
{
|
||||
return _fullname;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the class.
|
||||
/// </summary>
|
||||
StringAnsiView GetName() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the namespace of the class.
|
||||
/// </summary>
|
||||
StringAnsiView GetNamespace() const;
|
||||
|
||||
#if USE_MONO
|
||||
/// <summary>
|
||||
/// Gets the Mono class handle.
|
||||
@@ -81,6 +95,11 @@ public:
|
||||
{
|
||||
return _monoClass;
|
||||
}
|
||||
#elif USE_NETCORE
|
||||
FORCE_INLINE void* GetNative() const
|
||||
{
|
||||
return _handle;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
@@ -123,15 +142,34 @@ public:
|
||||
return _isInterface != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets if class is value type (eg. enum or structure) but not reference type (eg. class, string, array, interface)
|
||||
/// </summary>
|
||||
FORCE_INLINE bool IsValueType() const
|
||||
{
|
||||
return _isValueType != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets if class is enumeration
|
||||
/// </summary>
|
||||
FORCE_INLINE bool IsEnum() const
|
||||
{
|
||||
return _isEnum != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets if class is generic
|
||||
/// </summary>
|
||||
bool IsGeneric() const;
|
||||
bool IsGeneric() const
|
||||
{
|
||||
return _fullname.FindLast('`') != -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the class type.
|
||||
/// </summary>
|
||||
MType GetType() const;
|
||||
MType* GetType() const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the base class of this class. Null if this class has no base.
|
||||
@@ -142,17 +180,9 @@ public:
|
||||
/// Checks if this class is a sub class of the specified class (including any derived types).
|
||||
/// </summary>
|
||||
/// <param name="klass">The class.</param>
|
||||
/// <param name="checkInterfaces">True if check interfaces, otherwise just base class.</param>
|
||||
/// <returns>True if this class is a sub class of the specified class.</returns>
|
||||
bool IsSubClassOf(const MClass* klass) const;
|
||||
|
||||
#if USE_MONO
|
||||
/// <summary>
|
||||
/// Checks if this class is a sub class of the specified class (including any derived types).
|
||||
/// </summary>
|
||||
/// <param name="monoClass">The Mono class.</param>
|
||||
/// <returns>True if this class is a sub class of the specified class.</returns>
|
||||
bool IsSubClassOf(const MonoClass* monoClass) const;
|
||||
#endif
|
||||
bool IsSubClassOf(const MClass* klass, bool checkInterfaces = false) const;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this class implements the specified interface (including any base types).
|
||||
@@ -173,8 +203,12 @@ public:
|
||||
/// </summary>
|
||||
uint32 GetInstanceSize() const;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Returns the class of the array type elements.
|
||||
/// </summary>
|
||||
MClass* GetElementClass() const;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Returns an object referencing a method with the specified name and number of parameters. Optionally checks the base classes.
|
||||
/// </summary>
|
||||
@@ -182,7 +216,17 @@ public:
|
||||
/// <param name="numParams">The method parameters count.</param>
|
||||
/// <param name="checkBaseClasses">True if check base classes when searching for the given method.</param>
|
||||
/// <returns>The method or null if failed to find it.</returns>
|
||||
MMethod* FindMethod(const char* name, int32 numParams, bool checkBaseClasses);
|
||||
MMethod* FindMethod(const char* name, int32 numParams, bool checkBaseClasses = true) const
|
||||
{
|
||||
MMethod* method = GetMethod(name, numParams);
|
||||
if (!method && checkBaseClasses)
|
||||
{
|
||||
MClass* base = GetBaseClass();
|
||||
if (base)
|
||||
method = base->FindMethod(name, numParams, true);
|
||||
}
|
||||
return method;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an object referencing a method with the specified name and number of parameters.
|
||||
@@ -191,88 +235,73 @@ public:
|
||||
/// <param name="name">The method name.</param>
|
||||
/// <param name="numParams">The method parameters count.</param>
|
||||
/// <returns>The method or null if failed to get it.</returns>
|
||||
MMethod* GetMethod(const char* name, int32 numParams = 0);
|
||||
MMethod* GetMethod(const char* name, int32 numParams = 0) const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns all methods belonging to this class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Be aware this will not include the methods of any base classes.
|
||||
/// </remarks>
|
||||
/// <remarks>Be aware this will not include the methods of any base classes.</remarks>
|
||||
/// <returns>The list of methods.</returns>
|
||||
const Array<MMethod*>& GetMethods();
|
||||
const Array<MMethod*>& GetMethods() const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns an object referencing a field with the specified name.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Does not query base class fields.
|
||||
/// Returns null if field cannot be found.
|
||||
/// </remarks>
|
||||
/// <remarks>Does not query base class fields. Returns null if field cannot be found.</remarks>
|
||||
/// <param name="name">The field name.</param>
|
||||
/// <returns>The field or null if failed.</returns>
|
||||
MField* GetField(const char* name);
|
||||
MField* GetField(const char* name) const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns all fields belonging to this class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Be aware this will not include the fields of any base classes.
|
||||
/// </remarks>
|
||||
/// <remarks>Be aware this will not include the fields of any base classes.</remarks>
|
||||
/// <returns>The list of fields.</returns>
|
||||
const Array<MField*>& GetFields();
|
||||
const Array<MField*>& GetFields() const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns an object referencing a event with the specified name.
|
||||
/// </summary>
|
||||
/// <param name="name">The event name.</param>
|
||||
/// <returns>The event object.</returns>
|
||||
MEvent* GetEvent(const char* name);
|
||||
MEvent* GetEvent(const char* name) const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns all events belonging to this class.
|
||||
/// </summary>
|
||||
/// <returns>The list of events.</returns>
|
||||
const Array<MEvent*>& GetEvents();
|
||||
const Array<MEvent*>& GetEvents() const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns an object referencing a property with the specified name.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Does not query base class properties.
|
||||
/// Returns null if property cannot be found.
|
||||
/// </remarks>
|
||||
/// <remarks>Does not query base class properties. Returns null if property cannot be found.</remarks>
|
||||
/// <param name="name">The property name.</param>
|
||||
/// <returns>The property.</returns>
|
||||
MProperty* GetProperty(const char* name);
|
||||
MProperty* GetProperty(const char* name) const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns all properties belonging to this class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Be aware this will not include the properties of any base classes.
|
||||
/// </remarks>
|
||||
/// <remarks>Be aware this will not include the properties of any base classes.</remarks>
|
||||
/// <returns>The list of properties.</returns>
|
||||
const Array<MProperty*>& GetProperties();
|
||||
const Array<MProperty*>& GetProperties() const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns all interfaces implemented by this class (excluding interfaces from base classes).
|
||||
/// </summary>
|
||||
/// <remarks>Be aware this will not include the interfaces of any base classes.</remarks>
|
||||
/// <returns>The list of interfaces.</returns>
|
||||
const Array<MClass*>& GetInterfaces() const;
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of this class and constructs it.
|
||||
/// </summary>
|
||||
/// <returns>The created managed object.</returns>
|
||||
MObject* CreateInstance() const;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of this class and then constructs it using the constructor with the specified number of parameters.
|
||||
/// </summary>
|
||||
/// <param name="params">The array containing pointers to constructor parameters. Array length must be equal to number of parameters.</param>
|
||||
/// <param name="numParams">The number of parameters the constructor accepts.</param>
|
||||
/// <returns>The created managed object.</returns>
|
||||
MObject* CreateInstance(void** params, uint32 numParams);
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Checks if class has an attribute of the specified type.
|
||||
/// </summary>
|
||||
@@ -297,5 +326,5 @@ public:
|
||||
/// Returns an instance of all attributes connected with given class. Returns null if the class doesn't have any attributes.
|
||||
/// </summary>
|
||||
/// <returns>The array of attribute objects.</returns>
|
||||
const Array<MObject*>& GetAttributes();
|
||||
const Array<MObject*>& GetAttributes() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user