[Mono-dev] Embedding (iterating over assembly/image types)

Robert Jordan robertj at gmx.net
Tue Nov 25 13:25:34 EST 2008


MWheeler wrote:
> Hey all,
> I've been doing a bit of work with embedding mono into a game engine, and
> I'm yet to find a way (without using reflection 'inside' of C#/whatever) to
> iterate over all types in an assembly/image...  There's no reference to
> doing this in the documentation, and searching through the mini/metadata
> headers didn't unearth anything interesting.
> Is this supported by the mono API at present?

I wrote the following function for this purpose. It has the
same enumerator semantics like mono_class_get_methods.

#include <glib.h>
#include <mono/metadata/image.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/class.h>
#include <mono/metadata/tokentype.h>

  * Enumerates the classes of the specified assembly.
  * Similar to mono_class_get_{methods|fields|events|...}.
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) {
		return mono_class_get (image, *index | MONO_TOKEN_TYPE_DEF);
	} else {
		*index = 0;
		return NULL;


More information about the Mono-devel-list mailing list