[Mono-dev] Iterating the classes of a mono image using the embedding API

Robert Jordan robertj at gmx.net
Tue Dec 5 19:17:03 EST 2006

Argiris Kirtzidis wrote:
> On 12/05/06 Paolo Molaro wrote:
> I> terating the TypeDef table and calling mono_class_get () is the
> way to
>> go (I posted mostly the same sample code to a mono list a while
>> ago).
> Is there any chance an iterator function (like the
> 'mono_class_get_methods') gets added to the embedding API, so that
> you don't have to deal with internal stuff ? (thus not worry about
> your program breaking with a future version of Mono runtime)

I also thought that these functions and defines were internal,
but they aren't. Since the Mono API is quite stable, you don't need
to worry.

Anyway, here is the interator I'm using.


  * Iterator routine for retrieving the classes of an assembly.
  * Similar to mono_class_get_{methods|fields|events|...}.
mono_image_get_classes (MonoImage *image, gpointer *iter)
	int num_types;
	int *index;

	if (!iter)
		return NULL;

	index = (int *) iter;

	/* skip the <Module> */
	if (!*index)
		*index = 1;

	num_types = mono_image_get_table_rows (image, MONO_TABLE_TYPEDEF);

	if (*index < num_types) {
		return mono_class_get (image, *index | MONO_TOKEN_TYPE_DEF);
	} else {
		*index = 0;
		return NULL;


More information about the Mono-devel-list mailing list