[Mono-dev] how to coerce MonoObject* holding a System.Type to MonoClass*

Rodrigo Kumpera kumpera at gmail.com
Wed Dec 14 09:14:14 EST 2011


Hi Jonathan,

If you're using trunk, Zoltan Varga added a mono_reflection_type_get_type
to handle that.

On Tue, Dec 13, 2011 at 11:47 AM, Jonathan Shore
<jonathan.shore at gmail.com>wrote:

> Thanks.  That works
>
>
> On Mon, Dec 12, 2011 at 7:01 PM, Rodrigo Kumpera <kumpera at gmail.com>wrote:
>
>> There are two ways, you can do it from managed land directly:
>>
>> Type t = ...;
>> return t.TypeHandle.Value;
>>
>> This will give you a MonoType* (which is easy to convert to a MonoClass*).
>>
>> The other option is pretty shitty, due to a silly limitation in mono's
>> embedding API.
>> What you do is fetch the _impl field using mono_field_get_value
>>
>> MonoType *type;
>> mono_field_get_value (obj, _impl_field, &type);
>>
>>
>> On Tue, Dec 13, 2011 at 12:50 AM, Jonathan Shore <
>> jonathan.shore at gmail.com> wrote:
>>
>>>  I have a method call that returns System.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 mono_runtime_invoke() function returns aMonoObject*. 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.
>>>
>>> FYI: I posted this on stackoverflow @
>>> http://stackoverflow.com/questions/8483406/coercing-monoobject-to-monoclass-where-a-method-call-returns-a-typeif anyone cares to answer.
>>> Thanks
>>>
>>> Jonathan
>>>
>>> _______________________________________________
>>> Mono-devel-list mailing list
>>> Mono-devel-list at lists.ximian.com
>>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>>
>>>
>>
>
>
> --
> Jonathan Shore
> http://tr8dr.wordpress.com/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20111214/11dddd28/attachment-0001.html 


More information about the Mono-devel-list mailing list