[Mono-list] Iterating through classes in assembly
Robert Jordan
robertj at gmx.net
Fri May 27 06:42:36 EDT 2011
On 27.05.2011 07:47, JarkkoL wrote:
> Hi,
>
> I'm looking for a C function in libmono to iterate through classes in an
> assembly, but after reading through bunch of headers, documentation and
> googling around, I couldn't find such a function. There's
> mono_class_from_name() but that requires you know the class name beforehand,
> and I would like to provide users a generated list of classes to pick from,
> which requires some kind of iteration of the assembly for generating the
> list. There seems to be also mono_class_get_methods() which provides the
> functionality for iterating through methods of a class, but is there similar
> function for classes in an assembly?
There is no such function. You can either use
S.R.Assembly.GetExportedTypes ()´via mono_runtime_invoke (),
or something like this:
/*
* Enumerates the classes of the specified assembly.
* Similar to mono_class_get_{methods|fields|events|...}.
*/
static
MonoClass*
mono_assembly_get_classes (MonoAssembly *assembly, gpointer *iter)
{
MonoImage *image;
int num_types;
gssize *index;
if (!iter)
return NULL;
index = (gssize *) iter;
/* skip the <Module> */
if (!*index)
*index = 1;
image = mono_assembly_get_image (assembly);
num_types = mono_image_get_table_rows (image, MONO_TABLE_TYPEDEF);
if (*index < num_types) {
(*index)++;
return mono_class_get (image, *index | MONO_TOKEN_TYPE_DEF);
} else {
*index = 0;
return NULL;
}
}
Note that function is using old-style GLib types, so you'll probably
have to replace gpointer, gssize with... something else.
Robert
More information about the Mono-list
mailing list