class MonoUtil

Utility class containing methods for various common Mono/Script related operations.

Public

Methods

staticMonoToWString

static WString MonoToWString(MonoString *str)

Converts a Mono (managed) string to a native wide string.

staticMonoToString

static String MonoToString(MonoString *str)

Converts a Mono (managed) string to a native narrow string.

staticWstringToMono

static MonoString *WstringToMono(const WString &str)

Converts a native wide string to a Mono (managed) string.

staticWstringToMono

static MonoString *WstringToMono(const wchar_t *string)

Converts a native wide string to a Mono (managed) string.

staticStringToMono

static MonoString *StringToMono(const String &str)

Converts a native narrow string to a Mono (managed) string.

staticStringToMono

static MonoString *StringToMono(const char *string)

Converts a native narrow string to a Mono (managed) string.

staticGetClassName

static void GetClassName(MonoObject *obj, String &ns, String &typeName)

Outputs name and namespace for the type of the specified object.

staticGetClassName

static void GetClassName(::MonoClass *monoClass, String &ns, String &typeName)

Outputs name and namespace for the specified type.

staticGetClassName

static void GetClassName(MonoReflectionType *monoReflType, String &ns, String &typeName)

Outputs name and namespace for the specified type.

staticGetClass

static ::MonoClass *GetClass(MonoObject *object)

Returns the class of the provided object.

staticGetClass

static ::MonoClass *GetClass(MonoReflectionType *type)

Returns the class of the provided type.

staticGetType

static MonoReflectionType *GetType(MonoObject *object)

Returns the type of the provided object.

staticGetType

static MonoReflectionType *GetType(::MonoClass *klass)

Returns the type of the provided class.

staticNewGcHandle

static u32 NewGcHandle(MonoObject *object, bool pinned = true)

Creates a new GC handle for the provided managed object.

The handle can be stored and later used for retrieving the MonoObject* related to it by calling getObjectFromGCHandle(). This is a strong handle, meaning it will prevent the garbage collector from collecting the object until it is released by calling freeGCHandle().

object
Managed object to create the handle for.
pinned
If true the object will be pinned in memory, meaning you will be allowed to store a reference to the MonoObject directly. Never store MonoObject* unless they have been previously pinned (instead use getObjectFromGCHandle*( to get the current pointer). Note that pinning can have an impact on memory fragmentation as it prevents the GC from moving the object, so use it sparingly.

staticNewWeakGcHandle

static u32 NewWeakGcHandle(MonoObject *object)

Creates a new GC handle for the provided managed object.

The handle can be stored and later used for retrieving the MonoObject* related to it by calling getObjectFromGCHandle(). This is a weak handle, meaning it will NOT prevent the garbage collector from collecting the object. getObjectFromGCHandle() will return null if the GC collected the object and handle is no longer valid.

staticFreeGcHandle

static void FreeGcHandle(u32 handle)

Frees a GC handle previously allocated with newGCHandle.

staticGetObjectFromGcHandle

static MonoObject *GetObjectFromGcHandle(u32 handle)

Returns a MonoObject from an allocated GC handle.

staticBox

static MonoObject *Box(::MonoClass *klass, void *value)

Converts a managed value type into a reference type by boxing it.

staticUnbox

static void *Unbox(MonoObject *object)

Unboxes a managed object back to a raw value type.

staticValueCopy

static void ValueCopy(void *dest, void *src, ::MonoClass *klass)

Copies the value from to .

This must be a value-type of type . You need to use this form of copying if is a struct that gets passed to managed code and it contains a reference type. This way the GC is informed about the reference in the struct. You can use normal copies otherwise.

staticReferenceCopy

static void ReferenceCopy(void *dest, MonoObject *object)

Copies the pointer to a reference type to , ensuring also points to the object.

This needs to be used if is being passed to managed code (e.g. an output parameter in a method). Otherwise normal copies can be used. must be large enough to hold sizeof(MonoObject*).

staticIsSubClassOf

static bool IsSubClassOf(::MonoClass *subClass, ::MonoClass *parentClass)

Checks if this class is a sub class of the specified class.

staticIsValueType

static bool IsValueType(::MonoClass *object)

Checks is the specified class a value type.

staticIsEnum

static bool IsEnum(::MonoClass *object)

Checks is the specified class an enum.

staticGetEnumPrimitiveType

static MonoPrimitiveType GetEnumPrimitiveType(::MonoClass *enumClass)

Returns the underlying primitive type for an enum.

staticGetPrimitiveType

static MonoPrimitiveType GetPrimitiveType(::MonoClass *monoClass)

Returns the primitive type of the provided class.

staticGetPrimitiveTypeClass

static ::MonoClass *GetPrimitiveTypeClass(MonoPrimitiveType primitiveType)

Returns a corresponding primitive class type based on the provided enum.

staticGetPrimitiveTypeClass

static ::MonoClass *GetPrimitiveTypeClass(const String &typeName)

Returns a corresponding primitive class type based on the provided name (e.g. float, int, bool, etc.)

staticBindGenericParameters

static ::MonoClass *BindGenericParameters(::MonoClass *klass, ::MonoClass **params, u32 numParams)

Binds parameters to a generic class, and returns a new instantiable class with the bound parameters.

staticGetGenericParameters

static void GetGenericParameters(::MonoClass *klass, ::MonoClass **params, u32 &numParams)

Returns the generic parameters of the provided type. must be a pre-allocated buffer able to hold the class types for each parameter.

If is null, then will be populated with the number of available parameters.

staticGetGenericParameters

static void GetGenericParameters(::MonoReflectionType *type, ::MonoClass **params, u32 &numParams)

Returns the generic parameters of the provided type. must be a pre-allocated buffer able to hold the class types for each parameter.

If is null, then will be populated with the number of available parameters.

staticGetUint16Class

static ::MonoClass *GetUint16Class()

Returns Mono class for a 16-bit unsigned integer.

staticGetInt16Class

static ::MonoClass *GetInt16Class()

Returns Mono class for a 16-bit signed integer.

staticGetUint32Class

static ::MonoClass *GetUint32Class()

Returns Mono class for a 32-bit unsigned integer.

staticGetInt32Class

static ::MonoClass *GetInt32Class()

Returns Mono class for a 32-bit signed integer.

staticGetUint64Class

static ::MonoClass *GetUint64Class()

Returns Mono class for a 64-bit unsigned integer.

staticGetInt64Class

static ::MonoClass *GetInt64Class()

Returns Mono class for a 32-bit signed integer.

staticGetStringClass

static ::MonoClass *GetStringClass()

Returns Mono class for a string.

staticGetFloatClass

static ::MonoClass *GetFloatClass()

Returns Mono class for a floating point number.

staticGetDoubleClass

static ::MonoClass *GetDoubleClass()

Returns Mono class for a double floating point number.

staticGetBoolClass

static ::MonoClass *GetBoolClass()

Returns Mono class for a boolean.

staticGetByteClass

static ::MonoClass *GetByteClass()

Returns Mono class for an unsigned byte.

staticGetSByteClass

static ::MonoClass *GetSByteClass()

Returns Mono class for a byte.

staticGetCharClass

static ::MonoClass *GetCharClass()

Returns Mono class for a char.

staticGetObjectClass

static ::MonoClass *GetObjectClass()

Returns Mono class for a generic object.

staticThrowIfException

static void ThrowIfException(MonoException *exception)

staticThrowIfException

static void ThrowIfException(MonoObject *exception)

Throws a native exception if the provided object is a valid managed exception.