2004-09-02 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / metadata / class.c
index f1833d8c2f6a4f6e1b4c1a1b5f2ea5928b308992..cd99a2f1f273d19aceeec46fbcac9451b9e6ff70 100644 (file)
@@ -40,6 +40,7 @@ gboolean mono_print_vtable = FALSE;
 
 static MonoClass * mono_class_create_from_typedef (MonoImage *image, guint32 type_token);
 
+void (*mono_debugger_start_class_init_func) (MonoClass *klass) = NULL;
 void (*mono_debugger_class_init_func) (MonoClass *klass) = NULL;
 
 MonoClass *
@@ -57,16 +58,16 @@ mono_class_from_typeref (MonoImage *image, guint32 type_token)
        name = mono_metadata_string_heap (image, cols [MONO_TYPEREF_NAME]);
        nspace = mono_metadata_string_heap (image, cols [MONO_TYPEREF_NAMESPACE]);
        
-       idx = cols [MONO_TYPEREF_SCOPE] >> RESOLTION_SCOPE_BITS;
-       switch (cols [MONO_TYPEREF_SCOPE] & RESOLTION_SCOPE_MASK) {
-       case RESOLTION_SCOPE_MODULE:
+       idx = cols [MONO_TYPEREF_SCOPE] >> MONO_RESOLTION_SCOPE_BITS;
+       switch (cols [MONO_TYPEREF_SCOPE] & MONO_RESOLTION_SCOPE_MASK) {
+       case MONO_RESOLTION_SCOPE_MODULE:
                if (!idx)
                        g_error ("null ResolutionScope not yet handled");
                /* a typedef in disguise */
                return mono_class_from_name (image, nspace, name);
-       case RESOLTION_SCOPE_MODULEREF:
+       case MONO_RESOLTION_SCOPE_MODULEREF:
                return mono_class_from_name (image->modules [idx - 1], nspace, name);
-       case RESOLTION_SCOPE_TYPEREF: {
+       case MONO_RESOLTION_SCOPE_TYPEREF: {
                MonoClass *enclosing = mono_class_from_typeref (image, MONO_TOKEN_TYPE_REF | idx);
                GList *tmp;
                mono_class_init (enclosing);
@@ -78,7 +79,7 @@ mono_class_from_typeref (MonoImage *image, guint32 type_token)
                g_warning ("TypeRef ResolutionScope not yet handled (%d)", idx);
                return NULL;
        }
-       case RESOLTION_SCOPE_ASSEMBLYREF:
+       case MONO_RESOLTION_SCOPE_ASSEMBLYREF:
                break;
        }
 
@@ -113,12 +114,14 @@ dup_type (MonoType* t, const MonoType *original)
        MonoType *r = g_new0 (MonoType, 1);
        *r = *t;
        r->attrs = original->attrs;
+       r->byref = original->byref;
        mono_stats.generics_metadata_size += sizeof (MonoType);
        return r;
 }
 
 static void
-mono_type_get_name_recurse (MonoType *type, GString *str, gboolean is_recursed)
+mono_type_get_name_recurse (MonoType *type, GString *str, gboolean is_recursed,
+                           gboolean include_arity)
 {
        MonoClass *klass;
        
@@ -126,7 +129,8 @@ mono_type_get_name_recurse (MonoType *type, GString *str, gboolean is_recursed)
        case MONO_TYPE_ARRAY: {
                int i, rank = type->data.array->rank;
 
-               mono_type_get_name_recurse (&type->data.array->eklass->byval_arg, str, FALSE);
+               mono_type_get_name_recurse (
+                       &type->data.array->eklass->byval_arg, str, FALSE, include_arity);
                g_string_append_c (str, '[');
                for (i = 1; i < rank; i++)
                        g_string_append_c (str, ',');
@@ -134,47 +138,56 @@ mono_type_get_name_recurse (MonoType *type, GString *str, gboolean is_recursed)
                break;
        }
        case MONO_TYPE_SZARRAY:
-               mono_type_get_name_recurse (&type->data.klass->byval_arg, str, FALSE);
+               mono_type_get_name_recurse (
+                       &type->data.klass->byval_arg, str, FALSE, include_arity);
                g_string_append (str, "[]");
                break;
        case MONO_TYPE_PTR:
-               mono_type_get_name_recurse (type->data.type, str, FALSE);
+               mono_type_get_name_recurse (type->data.type, str, FALSE, include_arity);
                g_string_append_c (str, '*');
                break;
        default:
                klass = mono_class_from_mono_type (type);
                if (klass->nested_in) {
-                       mono_type_get_name_recurse (&klass->nested_in->byval_arg, str, TRUE);
+                       mono_type_get_name_recurse (
+                               &klass->nested_in->byval_arg, str, TRUE, include_arity);
                        g_string_append_c (str, '+');
                }
                if (*klass->name_space) {
                        g_string_append (str, klass->name_space);
                        g_string_append_c (str, '.');
                }
-               g_string_append (str, klass->name);
+               if (!include_arity) {
+                       char *s = strchr (klass->name, '`');
+                       int len = s ? s - klass->name : strlen (klass->name);
+
+                       g_string_append_len (str, klass->name, len);
+               } else
+                       g_string_append (str, klass->name);
                if (is_recursed)
                        break;
                if (klass->generic_inst) {
                        MonoGenericInst *ginst = klass->generic_inst;
                        int i;
 
-                       g_string_append_c (str, '[');
+                       g_string_append_c (str, '<');
                        for (i = 0; i < ginst->type_argc; i++) {
                                if (i)
                                        g_string_append_c (str, ',');
-                               mono_type_get_name_recurse (ginst->type_argv [i], str, FALSE);
+                               mono_type_get_name_recurse (
+                                       ginst->type_argv [i], str, FALSE, include_arity);
                        }
-                       g_string_append_c (str, ']');
+                       g_string_append_c (str, '>');
                } else if (klass->gen_params) {
                        int i;
 
-                       g_string_append_c (str, '[');
+                       g_string_append_c (str, '<');
                        for (i = 0; i < klass->num_gen_params; i++) {
                                if (i)
                                        g_string_append_c (str, ',');
                                g_string_append (str, klass->gen_params [i].name);
                        }
-                       g_string_append_c (str, ']');
+                       g_string_append_c (str, '>');
                }
                break;
        }
@@ -187,11 +200,11 @@ mono_type_get_name_recurse (MonoType *type, GString *str, gboolean is_recursed)
  * Returns the string representation for type as required by System.Reflection.
  * The inverse of mono_reflection_parse_type ().
  */
-char*
-mono_type_get_name (MonoType *type)
+static char*
+_mono_type_get_name (MonoType *type, gboolean is_recursed, gboolean include_arity)
 {
        GString* result = g_string_new ("");
-       mono_type_get_name_recurse (type, result, FALSE);
+       mono_type_get_name_recurse (type, result, is_recursed, include_arity);
 
        if (type->byref)
                g_string_append_c (result, '&');
@@ -199,6 +212,18 @@ mono_type_get_name (MonoType *type)
        return g_string_free (result, FALSE);
 }
 
+char*
+mono_type_get_name (MonoType *type)
+{
+       return _mono_type_get_name (type, TRUE, TRUE);
+}
+
+char*
+mono_type_get_full_name (MonoType *type)
+{
+       return _mono_type_get_name (type, FALSE, TRUE);
+}
+
 gboolean
 mono_class_is_open_constructed_type (MonoType *t)
 {
@@ -257,7 +282,7 @@ inflate_generic_type (MonoType *type, MonoGenericContext *context)
        }
        case MONO_TYPE_GENERICINST: {
                MonoGenericInst *oginst = type->data.generic_inst;
-               MonoGenericInst *nginst;
+               MonoGenericInst *nginst, *cached;
                MonoType *nt;
                int i;
 
@@ -282,12 +307,15 @@ inflate_generic_type (MonoType *type, MonoGenericContext *context)
                nginst->context->ginst = nginst;
 
                mono_loader_lock ();
-               nt = g_hash_table_lookup (oginst->klass->image->generic_inst_cache, nginst);
+               cached = g_hash_table_lookup (oginst->klass->image->generic_inst_cache, nginst);
 
-               if (nt) {
+               if (cached) {
                        g_free (nginst->type_argv);
                        g_free (nginst);
                        mono_loader_unlock ();
+
+                       nt = dup_type (type, type);
+                       nt->data.generic_inst = cached;
                        return nt;
                }
 
@@ -303,7 +331,7 @@ inflate_generic_type (MonoType *type, MonoGenericContext *context)
 
                nt = dup_type (type, type);
                nt->data.generic_inst = nginst;
-               g_hash_table_insert (oginst->klass->image->generic_inst_cache, nginst, nt);
+               g_hash_table_insert (oginst->klass->image->generic_inst_cache, nginst, nginst);
                mono_loader_unlock ();
                return nt;
        }
@@ -356,7 +384,6 @@ inflate_generic_header (MonoMethodHeader *header, MonoGenericContext *context)
        res->init_locals = header->init_locals;
        res->num_locals = header->num_locals;
        res->clauses = header->clauses;
-       res->gen_params = header->gen_params;
        for (i = 0; i < header->num_locals; ++i)
                res->locals [i] = mono_class_inflate_generic_type (header->locals [i], context);
        return res;
@@ -462,9 +489,13 @@ class_compute_field_layout (MonoClass *class)
                        class->instance_size = MAX (real_size, class->instance_size);
                }
                class->size_inited = 1;
+               class->blittable = blittable;
                return;
        }
 
+       if (layout == TYPE_ATTRIBUTE_AUTO_LAYOUT)
+               blittable = FALSE;
+
        class->fields = g_new0 (MonoClassField, top);
 
        /*
@@ -497,7 +528,7 @@ class_compute_field_layout (MonoClass *class)
 
                /* Only do these checks if we still think this type is blittable */
                if (blittable && !(field->type->attrs & FIELD_ATTRIBUTE_STATIC)) {
-                       if (field->type->byref) {
+                       if (field->type->byref || MONO_TYPE_IS_REFERENCE (field->type)) {
                                blittable = FALSE;
                        } else {
                                MonoClass *field_class = mono_class_from_mono_type (field->type);
@@ -516,7 +547,7 @@ class_compute_field_layout (MonoClass *class)
                        mono_metadata_field_info (m, idx, NULL, &rva, NULL);
                        if (!rva)
                                g_warning ("field %s in %s should have RVA data, but hasn't", field->name, class->name);
-                       field->data = mono_cli_rva_map (class->image->image_info, rva);
+                       field->data = mono_image_rva_map (class->image, rva);
                }
 
                if (class->enumtype && !(cols [MONO_FIELD_FLAGS] & FIELD_ATTRIBUTE_STATIC)) {
@@ -690,7 +721,7 @@ mono_class_layout_fields (MonoClass *class)
                int size, align;
                field = &class->fields [i];
                        
-               if (!(field->type->attrs & FIELD_ATTRIBUTE_STATIC))
+               if (!(field->type->attrs & FIELD_ATTRIBUTE_STATIC) || field->type->attrs & FIELD_ATTRIBUTE_LITERAL)
                        continue;
                if (mono_field_is_deleted (field))
                        continue;
@@ -1032,15 +1063,24 @@ mono_class_setup_vtable (MonoClass *class, MonoMethod **overrides, int onum)
 
                        for (l = 0; l < ic->method.count; l++) {
                                MonoMethod *im = ic->methods [l];                                               
-                               char *qname, *fqname;
+                               char *qname, *fqname, *cname, *the_cname;
                                MonoClass *k1;
                                
                                if (vtable [io + l])
                                        continue;
+
+                               if (ic->generic_inst) {
+                                       MonoClass *the_ic = mono_class_from_mono_type (ic->generic_inst->generic_type);
+                                       the_cname = _mono_type_get_name (&the_ic->byval_arg, TRUE, FALSE);
+                                       cname = the_cname;
+                               } else {
+                                       the_cname = NULL;
+                                       cname = ic->name;
+                               }
                                        
-                               qname = g_strconcat (ic->name, ".", im->name, NULL); 
+                               qname = g_strconcat (cname, ".", im->name, NULL);
                                if (ic->name_space && ic->name_space [0])
-                                       fqname = g_strconcat (ic->name_space, ".", ic->name, ".", im->name, NULL);
+                                       fqname = g_strconcat (ic->name_space, ".", cname, ".", im->name, NULL);
                                else
                                        fqname = NULL;
 
@@ -1059,6 +1099,7 @@ mono_class_setup_vtable (MonoClass *class, MonoMethod **overrides, int onum)
                                                }
                                        }
                                }
+                               g_free (the_cname);
                                g_free (qname);
                                g_free (fqname);
                        }
@@ -1298,6 +1339,9 @@ mono_class_init (MonoClass *class)
 
        class->init_pending = 1;
 
+       if (mono_debugger_start_class_init_func)
+               mono_debugger_start_class_init_func (class);
+
        mono_stats.initialized_class_count++;
 
        if (class->generic_inst && !class->generic_inst->is_dynamic) {
@@ -1456,6 +1500,10 @@ mono_class_init (MonoClass *class)
                 */
                setup_interface_offsets (class, 0);
                mono_loader_unlock ();
+
+               if (mono_debugger_class_init_func)
+                       mono_debugger_class_init_func (class);
+
                return;
        }
 
@@ -1523,7 +1571,6 @@ mono_class_init (MonoClass *class)
                mono_debugger_class_init_func (class);
 }
 
-
 void
 mono_class_setup_mono_type (MonoClass *class)
 {
@@ -1755,22 +1802,13 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token)
        }
 
        g_assert (mono_metadata_token_table (type_token) == MONO_TABLE_TYPEDEF);
-       
+
        mono_metadata_decode_row (tt, tidx - 1, cols, MONO_TYPEDEF_SIZE);
        
        name = mono_metadata_string_heap (image, cols [MONO_TYPEDEF_NAME]);
        nspace = mono_metadata_string_heap (image, cols [MONO_TYPEDEF_NAMESPACE]);
 
-       if (cols [MONO_TYPEDEF_EXTENDS])
-               parent = mono_class_get (image, mono_metadata_token_from_dor (cols [MONO_TYPEDEF_EXTENDS]));
-       interfaces = mono_metadata_interfaces_from_typedef (image, type_token, &icount);
-
        class = g_malloc0 (sizeof (MonoClass));
-                          
-       g_hash_table_insert (image->class_cache, GUINT_TO_POINTER (type_token), class);
-
-       class->interfaces = interfaces;
-       class->interface_count = icount;
 
        class->name = name;
        class->name_space = nspace;
@@ -1779,6 +1817,15 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token)
        class->type_token = type_token;
        class->flags = cols [MONO_TYPEDEF_FLAGS];
 
+       g_hash_table_insert (image->class_cache, GUINT_TO_POINTER (type_token), class);
+
+       if (cols [MONO_TYPEDEF_EXTENDS])
+               parent = mono_class_get (image, mono_metadata_token_from_dor (cols [MONO_TYPEDEF_EXTENDS]));
+       interfaces = mono_metadata_interfaces_from_typedef (image, type_token, &icount);
+
+       class->interfaces = interfaces;
+       class->interface_count = icount;
+
        if ((class->flags & TYPE_ATTRIBUTE_STRING_FORMAT_MASK) == TYPE_ATTRIBUTE_UNICODE_CLASS)
                class->unicode = 1;
        /* fixme: maybe we must set this on windows 
@@ -1970,8 +2017,8 @@ mono_ptr_class_get (MonoType *type)
        result = g_new0 (MonoClass, 1);
 
        result->parent = NULL; /* no parent for PTR types */
-       result->name = "System";
-       result->name_space = "MonoPtrFakeClass";
+       result->name_space = el_class->name_space;
+       result->name = g_strdup_printf ("%s*", el_class->name);
        result->image = el_class->image;
        result->inited = TRUE;
        result->flags = TYPE_ATTRIBUTE_CLASS | (el_class->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK);
@@ -2016,7 +2063,7 @@ mono_fnptr_class_get (MonoMethodSignature *sig)
        result->name_space = "MonoFNPtrFakeClass";
        result->image = NULL; /* need to fix... */
        result->inited = TRUE;
-       result->flags = TYPE_ATTRIBUTE_CLASS; // | (el_class->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK);
+       result->flags = TYPE_ATTRIBUTE_CLASS; /* | (el_class->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK); */
        /* Can pointers get boxed? */
        result->instance_size = sizeof (gpointer);
        result->cast_class = result->element_class = result;
@@ -2124,7 +2171,7 @@ mono_class_create_from_typespec (MonoImage *image, guint32 type_spec,
                class = mono_array_class_get (type->data.klass, 1);
                break;
        case MONO_TYPE_PTR:
-               class = mono_class_from_mono_type (type->data.type);
+               class = mono_ptr_class_get (type->data.type);
                break;
        case MONO_TYPE_GENERICINST:
                g_assert (type->data.generic_inst->klass);
@@ -2390,6 +2437,12 @@ mono_class_get_field_from_name (MonoClass *klass, const char *name)
        return NULL;
 }
 
+void *
+mono_vtable_get_static_field_data (MonoVTable *vt)
+{
+       return vt->data;
+}
+
 MonoProperty*
 mono_class_get_property_from_name (MonoClass *klass, const char *name)
 {
@@ -2470,6 +2523,22 @@ mono_class_get_full (MonoImage *image, guint32 type_token, MonoGenericContext *c
        return mono_class_from_mono_type (inflated);
 }
 
+/**
+ * mono_class_from_name_case:
+ * @image: The MonoImage where the type is looked up in, or NULL for looking up in all loaded assemblies
+ * @name_space: the type namespace
+ * @name: the type short name.
+ *
+ * Obtains a MonoClass with a given namespace and a given name which
+ * is located in the given MonoImage.   The namespace and name
+ * lookups are case insensitive.
+ *
+ * You can also pass `NULL' to the image, and that will lookup for
+ * a type with the given namespace and name in all of the loaded
+ * assemblies: notice that since there might be a name clash in this
+ * case, passing NULL is not encouraged if you need a precise type.
+ *
+ */
 MonoClass *
 mono_class_from_name_case (MonoImage *image, const char* name_space, const char *name)
 {
@@ -2515,6 +2584,22 @@ return_nested_in (MonoClass *class, char *nested) {
        return NULL;
 }
 
+
+/**
+ * mono_class_from_name_case:
+ * @image: The MonoImage where the type is looked up in, or NULL for looking up in all loaded assemblies
+ * @name_space: the type namespace
+ * @name: the type short name.
+ *
+ * Obtains a MonoClass with a given namespace and a given name which
+ * is located in the given MonoImage.   
+ *
+ * You can also pass `NULL' to the image, and that will lookup for
+ * a type with the given namespace and name in all of the loaded
+ * assemblies: notice that since there might be a name clash in this
+ * case, passing NULL is not encouraged if you need a precise type.
+ *
+ */
 MonoClass *
 mono_class_from_name (MonoImage *image, const char* name_space, const char *name)
 {
@@ -2558,8 +2643,8 @@ mono_class_from_name (MonoImage *image, const char* name_space, const char *name
                mono_metadata_decode_row (t, idx - 1, cols, MONO_EXP_TYPE_SIZE);
 
                impl = cols [MONO_EXP_TYPE_IMPLEMENTATION];
-               if ((impl & IMPLEMENTATION_MASK) == IMPLEMENTATION_FILE) {
-                       loaded_image = mono_assembly_load_module (image->assembly, impl >> IMPLEMENTATION_BITS);
+               if ((impl & MONO_IMPLEMENTATION_MASK) == MONO_IMPLEMENTATION_FILE) {
+                       loaded_image = mono_assembly_load_module (image->assembly, impl >> MONO_IMPLEMENTATION_BITS);
                        if (!loaded_image)
                                return NULL;
                        class = mono_class_from_name (loaded_image, name_space, name);
@@ -2599,16 +2684,6 @@ mono_class_is_subclass_of (MonoClass *klass, MonoClass *klassc,
        } else {
                if (!MONO_CLASS_IS_INTERFACE (klass) && mono_class_has_parent (klass, klassc))
                        return TRUE;
-               if (klass->generic_inst) {
-                       MonoType *parent = klass->generic_inst->parent;
-                       if (!parent)
-                               return FALSE;
-
-                       if (mono_metadata_type_equal (parent, &klassc->byval_arg))
-                               return TRUE;
-                       klass = mono_class_from_mono_type (parent);
-                       goto again;
-               }
        }
 
        /* 
@@ -2617,6 +2692,17 @@ mono_class_is_subclass_of (MonoClass *klass, MonoClass *klassc,
         */
        if (klassc == mono_defaults.object_class)
                return TRUE;
+
+       if (klass->generic_inst) {
+               MonoType *parent = klass->generic_inst->parent;
+               if (!parent)
+                       return FALSE;
+
+               if (mono_metadata_type_equal (parent, &klassc->byval_arg))
+                       return TRUE;
+               klass = mono_class_from_mono_type (parent);
+               goto again;
+       }
        
        return FALSE;
 }
@@ -2701,10 +2787,10 @@ mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller)
 gint32
 mono_class_array_element_size (MonoClass *klass)
 {
-       int t = klass->byval_arg.type;
+       MonoType *type = &klass->byval_arg;
        
 handle_enum:
-       switch (t) {
+       switch (type->type) {
        case MONO_TYPE_I1:
        case MONO_TYPE_U1:
        case MONO_TYPE_BOOLEAN:
@@ -2733,13 +2819,16 @@ handle_enum:
        case MONO_TYPE_R8:
                return 8;
        case MONO_TYPE_VALUETYPE:
-               if (klass->enumtype) {
-                       t = klass->enum_basetype->type;
+               if (type->data.klass->enumtype) {
+                       type = type->data.klass->enum_basetype;
                        goto handle_enum;
                }
-               return mono_class_instance_size (klass) - sizeof (MonoObject);
+               return mono_class_instance_size (type->data.klass) - sizeof (MonoObject);
+       case MONO_TYPE_GENERICINST:
+               type = type->data.generic_inst->generic_type;
+               goto handle_enum;
        default:
-               g_error ("unknown type 0x%02x in mono_class_array_element_size", t);
+               g_error ("unknown type 0x%02x in mono_class_array_element_size", type->type);
        }
        return -1;
 }
@@ -2870,78 +2959,216 @@ mono_class_get_image (MonoClass *klass)
        return klass->image;
 }
 
+/**
+ * mono_class_get_element_class:
+ * @klass: the MonoClass to act on
+ *
+ * Returns the element class of an array or an enumeration.
+ */
 MonoClass*
 mono_class_get_element_class (MonoClass *klass)
 {
        return klass->element_class;
 }
 
+/**
+ * mono_class_is_valuetype:
+ * @klass: the MonoClass to act on
+ *
+ * Returns true if the MonoClass represents a ValueType.
+ */
 gboolean
 mono_class_is_valuetype (MonoClass *klass)
 {
        return klass->valuetype;
 }
 
+/**
+ * mono_class_is_enum:
+ * @klass: the MonoClass to act on
+ *
+ * Returns true if the MonoClass represents an enumeration.
+ */
 gboolean
 mono_class_is_enum (MonoClass *klass)
 {
        return klass->enumtype;
 }
 
+/**
+ * mono_class_enum_basetype:
+ * @klass: the MonoClass to act on
+ *
+ * Returns the underlying type representation for an enumeration.
+ */
 MonoType*
 mono_class_enum_basetype (MonoClass *klass)
 {
        return klass->enum_basetype;
 }
 
+/**
+ * mono_class_get_parent
+ * @klass: the MonoClass to act on
+ *
+ * Returns the parent class for this class.
+ */
 MonoClass*
 mono_class_get_parent (MonoClass *klass)
 {
        return klass->parent;
 }
 
+/**
+ * mono_class_get_nesting_type;
+ * @klass: the MonoClass to act on
+ *
+ * Returns the container type where this type is nested or NULL if this type is not a nested type.
+ */
 MonoClass*
 mono_class_get_nesting_type (MonoClass *klass)
 {
        return klass->nested_in;
 }
 
+/**
+ * mono_class_get_rank:
+ * @klass: the MonoClass to act on
+ *
+ * Returns the rank for the array (the number of dimensions).
+ */
 int
 mono_class_get_rank (MonoClass *klass)
 {
        return klass->rank;
 }
 
+/**
+ * mono_class_get_flags:
+ * @klass: the MonoClass to act on
+ *
+ * The type flags from the TypeDef table from the metadata.
+ * see the TYPE_ATTRIBUTE_* definitions on tabledefs.h for the
+ * different values.
+ *
+ * Returns the flags from the TypeDef table.
+ */
 guint32
 mono_class_get_flags (MonoClass *klass)
 {
        return klass->flags;
 }
 
+/**
+ * mono_class_get_name
+ * @klass: the MonoClass to act on
+ *
+ * Returns the name of the class.
+ */
 const char*
 mono_class_get_name (MonoClass *klass)
 {
        return klass->name;
 }
 
+/**
+ * mono_class_get_namespace:
+ * @klass: the MonoClass to act on
+ *
+ * Returns the namespace of the class.
+ */
 const char*
 mono_class_get_namespace (MonoClass *klass)
 {
        return klass->name_space;
 }
 
+/**
+ * mono_class_get_type:
+ * @klass: the MonoClass to act on
+ *
+ * This method returns the internal Type representation for the class.
+ *
+ * Returns the MonoType from the class.
+ */
 MonoType*
 mono_class_get_type (MonoClass *klass)
 {
        return &klass->byval_arg;
 }
 
+/**
+ * mono_class_get_byref_type:
+ * @klass: the MonoClass to act on
+ *
+ * 
+ */
 MonoType*
 mono_class_get_byref_type (MonoClass *klass)
 {
        return &klass->this_arg;
 }
 
+/**
+ * mono_class_num_fields:
+ * @klass: the MonoClass to act on
+ *
+ * Returns the number of static and instance fields in the class.
+ */
+int
+mono_class_num_fields (MonoClass *klass)
+{
+       return klass->field.count;
+}
+
+/**
+ * mono_class_num_methods:
+ * @klass: the MonoClass to act on
+ *
+ * Returns the number of methods in the class.
+ */
+int
+mono_class_num_methods (MonoClass *klass)
+{
+       return klass->method.count;
+}
+
+/**
+ * mono_class_num_properties
+ * @klass: the MonoClass to act on
+ *
+ * Returns the number of properties in the class.
+ */
+int
+mono_class_num_properties (MonoClass *klass)
+{
+       return klass->property.count;
+}
+
+/**
+ * mono_class_num_events:
+ * @klass: the MonoClass to act on
+ *
+ * Returns the number of events in the class.
+ */
+int
+mono_class_num_events (MonoClass *klass)
+{
+       return klass->event.count;
+}
+
+/**
+ * mono_class_get_fields:
+ * @klass: the MonoClass to act on
+ *
+ * This routine is an iterator routine for retrieving the fields in a class.
+ *
+ * You must pass a gpointer that points to zero and is treated as an opaque handle to
+ * iterate over all of the elements.  When no more values are
+ * available, the return value is NULL.
+ *
+ * Returns a `MonoClassField *' on each iteration, or NULL when no more fields are available.
+ */
 MonoClassField*
 mono_class_get_fields (MonoClass* klass, gpointer *iter)
 {
@@ -2967,6 +3194,18 @@ mono_class_get_fields (MonoClass* klass, gpointer *iter)
        return NULL;
 }
 
+/**
+ * mono_class_get_methods
+ * @klass: the MonoClass to act on
+ *
+ * This routine is an iterator routine for retrieving the fields in a class.
+ *
+ * You must pass a gpointer that points to zero and is treated as an opaque handle to
+ * iterate over all of the elements.  When no more values are
+ * available, the return value is NULL.
+ *
+ * Returns a MonoMethod on each iteration or NULL when no more methods are available.
+ */
 MonoMethod*
 mono_class_get_methods (MonoClass* klass, gpointer *iter)
 {
@@ -2994,6 +3233,18 @@ mono_class_get_methods (MonoClass* klass, gpointer *iter)
        return NULL;
 }
 
+/**
+ * mono_class_get_properties:
+ * @klass: the MonoClass to act on
+ *
+ * This routine is an iterator routine for retrieving the properties in a class.
+ *
+ * You must pass a gpointer that points to zero and is treated as an opaque handle to
+ * iterate over all of the elements.  When no more values are
+ * available, the return value is NULL.
+ *
+ * Returns a `MonoProperty *' on each invocation, or NULL when no more are available.
+ */
 MonoProperty*
 mono_class_get_properties (MonoClass* klass, gpointer *iter)
 {
@@ -3019,6 +3270,18 @@ mono_class_get_properties (MonoClass* klass, gpointer *iter)
        return NULL;
 }
 
+/**
+ * mono_class_get_events:
+ * @klass: the MonoClass to act on
+ *
+ * This routine is an iterator routine for retrieving the properties in a class.
+ *
+ * You must pass a gpointer that points to zero and is treated as an opaque handle to
+ * iterate over all of the elements.  When no more values are
+ * available, the return value is NULL.
+ *
+ * Returns a `MonoEvent *' on each invocation, or NULL when no more are available.
+ */
 MonoEvent*
 mono_class_get_events (MonoClass* klass, gpointer *iter)
 {
@@ -3044,6 +3307,18 @@ mono_class_get_events (MonoClass* klass, gpointer *iter)
        return NULL;
 }
 
+/**
+ * mono_class_get_interfaaces
+ * @klass: the MonoClass to act on
+ *
+ * This routine is an iterator routine for retrieving the interfaces implemented by this class.
+ *
+ * You must pass a gpointer that points to zero and is treated as an opaque handle to
+ * iterate over all of the elements.  When no more values are
+ * available, the return value is NULL.
+ *
+ * Returns a `Monoclass *' on each invocation, or NULL when no more are available.
+ */
 MonoClass*
 mono_class_get_interfaces (MonoClass* klass, gpointer *iter)
 {
@@ -3071,6 +3346,18 @@ mono_class_get_interfaces (MonoClass* klass, gpointer *iter)
        return NULL;
 }
 
+/**
+ * mono_class_get_interfaaces
+ * @klass: the MonoClass to act on
+ *
+ * This routine is an iterator routine for retrieving the nested types of a class.
+ *
+ * You must pass a gpointer that points to zero and is treated as an opaque handle to
+ * iterate over all of the elements.  When no more values are
+ * available, the return value is NULL.
+ *
+ * Returns a `Monoclass *' on each invocation, or NULL when no more are available.
+ */
 MonoClass*
 mono_class_get_nested_types (MonoClass* klass, gpointer *iter)
 {
@@ -3098,90 +3385,189 @@ mono_class_get_nested_types (MonoClass* klass, gpointer *iter)
        return NULL;
 }
 
+/**
+ * mono_field_get_name:
+ * @field: the MonoClassField to act on
+ *
+ * Returns the name of the field.
+ */
 const char*
 mono_field_get_name (MonoClassField *field)
 {
        return field->name;
 }
 
+/**
+ * mono_field_get_type:
+ * @field: the MonoClassField to act on
+ *
+ * Returns MonoType of the field.
+ */
 MonoType*
 mono_field_get_type (MonoClassField *field)
 {
        return field->type;
 }
 
+/**
+ * mono_field_get_type:
+ * @field: the MonoClassField to act on
+ *
+ * Returns MonoClass where the field was defined.
+ */
 MonoClass*
 mono_field_get_parent (MonoClassField *field)
 {
        return field->parent;
 }
 
+/**
+ * mono_field_get_flags;
+ * @field: the MonoClassField to act on
+ *
+ * The metadata flags for a field are encoded using the
+ * FIELD_ATTRIBUTE_* constants.  See the tabledefs.h file for details.
+ *
+ * Returns the flags for the field.
+ */
 guint32
 mono_field_get_flags (MonoClassField *field)
 {
        return field->type->attrs;
 }
 
+/**
+ * mono_property_get_name: 
+ * @prop: the MonoProperty to act on
+ *
+ * Returns the name of the property
+ */
 const char*
 mono_property_get_name (MonoProperty *prop)
 {
        return prop->name;
 }
 
+/**
+ * mono_property_get_set_method
+ * @prop: the MonoProperty to act on.
+ *
+ * Returns the setter method of the property (A MonoMethod)
+ */
 MonoMethod*
 mono_property_get_set_method (MonoProperty *prop)
 {
        return prop->set;
 }
 
+/**
+ * mono_property_get_get_method
+ * @prop: the MonoProperty to act on.
+ *
+ * Returns the setter method of the property (A MonoMethod)
+ */
 MonoMethod*
 mono_property_get_get_method (MonoProperty *prop)
 {
        return prop->get;
 }
 
+/**
+ * mono_property_get_parent:
+ * @prop: the MonoProperty to act on.
+ *
+ * Returns the MonoClass where the property was defined.
+ */
 MonoClass*
 mono_property_get_parent (MonoProperty *prop)
 {
        return prop->parent;
 }
 
+/**
+ * mono_property_get_flags:
+ * @prop: the MonoProperty to act on.
+ *
+ * The metadata flags for a property are encoded using the
+ * PROPERTY_ATTRIBUTE_* constants.  See the tabledefs.h file for details.
+ *
+ * Returns the flags for the property.
+ */
 guint32
 mono_property_get_flags (MonoProperty *prop)
 {
        return prop->attrs;
 }
 
+/**
+ * mono_event_get_name:
+ * @event: the MonoEvent to act on
+ *
+ * Returns the name of the event.
+ */
 const char*
 mono_event_get_name (MonoEvent *event)
 {
        return event->name;
 }
 
+/**
+ * mono_event_get_add_method:
+ * @event: The MonoEvent to act on.
+ *
+ * Returns the `add' method for the event (a MonoMethod).
+ */
 MonoMethod*
 mono_event_get_add_method (MonoEvent *event)
 {
        return event->add;
 }
 
+/**
+ * mono_event_get_remove_method:
+ * @event: The MonoEvent to act on.
+ *
+ * Returns the `remove' method for the event (a MonoMethod).
+ */
 MonoMethod*
 mono_event_get_remove_method (MonoEvent *event)
 {
        return event->remove;
 }
 
+/**
+ * mono_event_get_raise_method:
+ * @event: The MonoEvent to act on.
+ *
+ * Returns the `raise' method for the event (a MonoMethod).
+ */
 MonoMethod*
 mono_event_get_raise_method (MonoEvent *event)
 {
        return event->raise;
 }
 
+/**
+ * mono_event_get_parent:
+ * @event: the MonoEvent to act on.
+ *
+ * Returns the MonoClass where the event is defined.
+ */
 MonoClass*
 mono_event_get_parent (MonoEvent *event)
 {
        return event->parent;
 }
 
+/**
+ * mono_event_get_flags
+ * @event: the MonoEvent to act on.
+ *
+ * The metadata flags for an event are encoded using the
+ * EVENT_* constants.  See the tabledefs.h file for details.
+ *
+ * Returns the flags for the event.
+ */
 guint32
 mono_event_get_flags (MonoEvent *event)
 {