I have a method call that returns Type. I want to make use of the type and do some reflection from C++. Have code like this:
MonoClass* klass = (MonoClass*)mono_runtime_invoke (...);
I am pretty sure that the casting to MonoClass* is not appropriate. The function returns a MonoObject*. How do I coerce the MonoObject* containing a reference to Type to MonoClass*. I want to be able to be able to call:
mono_class_get_properties (type, &iter)
iteratively, later.
Solution 1
If you have an access to the .NET code, the simpliest way is to return the type’s TypeHandle. In the native code, you can access the
MonoTypeby unboxing the result of the invocation.In C#:
In native code:
Solution 2
If you cannot change the .NET code, then you have to call the
TypeHandleandValuegetters in native code.