How to create a shared list of <String> object using mono-inline calls? I can get a list of MonoClass:
MonoClass* list = mono_class_from_name(mscorlibimage, "System.Collections.Generic", "List`1");
and I see in the documents that there
mono_class_from_generic_parameter(MonoGenericParam*...)
but I have no idea where and how to get MonoGenericParam. Or maybe I need to create a valid name for mono_class_from_name? I think this might be a little slower, but I would agree to that. I tried
MonoClass* list = mono_class_from_name(mscorlib::get().image, "System.Collections.Generic", "List`1[System.String]");
but no luck.
UPDATE:
OK I found a way. However, I would like to see if there is an official way to do something, as this hack looks too dirty for me.
Basically I searched for mono sources for common methods and found mono_class_bind_generic_parameters (see https://raw.github.com/mono/mono/master/mono/metadata/reflection.c ). I had to reference libmono-2.0.a in addition to .so to use it. But it worked:
extern "C" MonoClass* mono_class_bind_generic_parameters(MonoClass *klass, int type_argc, MonoType **types, bool is_dynamic); MonoClass* list = mono_class_from_name(mscorlib::get().image, "System.Collections.Generic", "List`1"); MonoClass* strcls = mono_class_from_name(mscorlib::get().image, "System", "String"); printf("str class: %p\n", strcls); MonoType* strtype = mono_class_get_type(strcls); printf("str type: %p\n", strtype); MonoType* types[1]; types[0] = strtype; list = mono_class_bind_generic_parameters(list, 1, types, false); printf("list[string] class: %p\n", list); MonoObject* obj = mono_object_new(domain, list); printf("list[string] created: %p\n", obj);
I believe that I can use the sources (UPDATE: unlikely) of these methods and redefine them (they analyze metadata, etc.) - if I do not want to refer to .a - but I wonder if there is an easier way. Mono documents simply do not respond as they use.
UPDATE: found this chain: http://mono.1490590.n4.nabble.com/Embedded-API-Method-signature-not-found-with-generic-parameter-td4660157.html , which does not seem to contain any built-in API for what I want (i.e. they donβt bother to set mono_class_bind_generic_parameters). Can anyone prove that this is correct? With this method, by the way, I get MonoReflectionType * and do not get MonoType * from it, while it is as easy as get-> type from a structure that is internal and access through functions to it is internal. Instead, Mono Embedded should be called "Mono Internal."
UPDATE: another way to crack a mono_class_inflate_generic_type file using a copy of internal structures:
struct _MonoGenericInst { uint32_t id; uint32_t type_argc : 22; uint32_t is_open : 1; MonoType *type_argv [1]; }; struct _MonoGenericContext { MonoGenericInst *class_inst; void *method_inst; }; _MonoGenericInst clsctx; clsctx.type_argc = 1; clsctx.is_open = 0; clsctx.type_argv[0] = mono_class_get_type(System::String::_SClass()); MonoGenericContext ctx; ctx.method_inst = 0; ctx.class_inst = &clsctx; MonoType* lt = mono_class_inflate_generic_type( mono_class_get_type(System::Collections::Generic::List<System::String>::_SClass()), &ctx);
This does not require a static reference to .a, but it is even worse. And mono_class_inflate_generic_type is labeled DEPRECATED - so if it is deprecated, then which one is modern?