# mono-api-metadata.html

# Metadata Reading

The Metadata API gives developers low-level access to the information encoded in CLI modules: type and methods definitions encoded in metadata as well as access to the CIL code and embedded resources.

Managed developers access this information using either the System.Reflection API or a library like Cecil.

To start using the Metadata API it is necessary to open an assembly or a CIL image (a .dll or .exe file) using one of the CIL image opening API calls.

## Metadata Heaps

ECMA CLI images contain four heaps that store different kinds of information, these are:

- GUID heap (called #GUID) contains 128-bit GUIDs, you can get pointer to a GUID value by calling mono_metadata_guid_heap.
- User string heap (called #US), it contains user visible strings, you can fetch a string from this heap by calling mono_metadata_user_string.
- Blob heap (called #blob), it contains binary blobs of data, you can get a blob by mono_metadata_blob_heap. You can determine the size of the blob using the mono_metadata_decode_blob_size.

The ECMA file format also has an extra section called the "#~" stream, this stream is the one that holds the metadata tables. There is a high-level API to get access to the contents of this API, described in the section Metadata Tables.
`mono_metadata_guid_heap`
Syntax
const char * mono_metadata_guid_heap (MonoImage *meta, guint32 index)

Parameters

meta | metadata context
index | index into the guid heap.

Return value
an in-memory pointer to the index in the guid heap.
`mono_metadata_string_heap`
Syntax
const char * mono_metadata_string_heap (MonoImage *meta, guint32 index)

Parameters

meta | metadata context
index | index into the string heap.

Return value
an in-memory pointer to the index in the string heap.
`mono_metadata_blob_heap`
Syntax
const char * mono_metadata_blob_heap (MonoImage *meta, guint32 index)

Parameters

meta | metadata context
index | index into the blob.

Return value
an in-memory pointer to the index in the Blob heap.
`mono_metadata_user_string`
Syntax
const char * mono_metadata_user_string (MonoImage *meta, guint32 index)

Parameters

meta | metadata context
index | index into the user string heap.

Return value
an in-memory pointer to the index in the user string heap (``US``).
`mono_metadata_decode_blob_size`
Syntax
guint32 mono_metadata_decode_blob_size (const char *xptr, const char **rptr)

Parameters

ptr | pointer to a blob object
rptr | the new position of the pointer

Return value
the size of the blob object
Description

This decodes a compressed size as described by 24.2.4 (`US` and `Blob` a blob or user string object)

## Metadata Tables

Metadata is encoded in a number of tables included on every CIL image. These tables contain type definitions, member definitions and so on, these constants are defined in the ECMA 335 specification Partition II section 22. The following table shows the C constants defined in the Mono runtime and how they map to the equivalent ECMA CLI metadata table:

ECMA CLI Table Name

C Constant Name

Table Schema (Array Size + Columns Constants)

Assembly

MONO_TABLE_ASSEMBLY

Array size: MONO_ASSEMBLY_SIZE

- MONO_ASSEMBLY_HASH_ALG
- MONO_ASSEMBLY_MAJOR_VERSION
- MONO_ASSEMBLY_MINOR_VERSION
- MONO_ASSEMBLY_BUILD_NUMBER
- MONO_ASSEMBLY_REV_NUMBER
- MONO_ASSEMBLY_FLAGS
- MONO_ASSEMBLY_PUBLIC_KEY
- MONO_ASSEMBLY_NAME
- MONO_ASSEMBLY_CULTURE

AssemblyOS

MONO_TABLE_ASSEMBLYOS

Array size: MONO_ASSEMBLYOS_SIZE

- MONO_ASSEMBLYOS_PLATFORM
- MONO_ASSEMBLYOS_MAJOR_VERSION
- MONO_ASSEMBLYOS_MINOR_VERSION

AssemblyProcessor

MONO_TABLE_ASSEMBLYPROCESSOR

Array size: MONO_ASSEMBLYPROCESSOR_SIZE

- MONO_ASSEMBLY_PROCESSOR

AssemblyRef

MONO_TABLE_ASSEMBLYREF

Array size: MONO_ASSEMBLYREF_SIZE

- MONO_ASSEMBLYREF_MAJOR_VERSION
- MONO_ASSEMBLYREF_MINOR_VERSION
- MONO_ASSEMBLYREF_BUILD_NUMBER
- MONO_ASSEMBLYREF_REV_NUMBER
- MONO_ASSEMBLYREF_FLAGS
- MONO_ASSEMBLYREF_PUBLIC_KEY
- MONO_ASSEMBLYREF_NAME
- MONO_ASSEMBLYREF_CULTURE
- MONO_ASSEMBLYREF_HASH_VALUE

AssemblyRefProcessor

MONO_TABLE_ASSEMBLYREFPROCESSOR

Array size: MONO_ASSEMBLYREFPROC_SIZE

- MONO_ASSEMBLYREFPROC_PROCESSOR
- MONO_ASSEMBLYREFPROC_ASSEMBLYREF

AssemblyRefOS

MONO_TABLE_ASSEMBLYREFOS

Array size:
- MONO_ASSEMBLYREFOS_SIZE
  - MONO_ASSEMBLYREFOS_PLATFORM
  - MONO_ASSEMBLYREFOS_MAJOR_VERSION
  - MONO_ASSEMBLYREFOS_MINOR_VERSION
  - MONO_ASSEMBLYREFOS_ASSEMBLYREF

ClassLayout

MONO_TABLE_CLASSLAYOUT

Array size: MONO_CLASSLAYOUT_SIZE

- MONO_CLASS_LAYOUT_PACKING_SIZE
- MONO_CLASS_LAYOUT_CLASS_SIZE
- MONO_CLASS_LAYOUT_PARENT

Constant

MONO_TABLE_CONSTANT

Array size: MONO_CONSTANT_SIZE

- MONO_CONSTANT_TYPE
- MONO_CONSTANT_PADDING
- MONO_CONSTANT_PARENT
- MONO_CONSTANT_VALUE

CustomAttribute

MONO_TABLE_CUSTOMATTRIBUTE

Array size: MONO_CUSTOM_ATTR_SIZE

- MONO_CUSTOM_ATTR_PARENT
- MONO_CUSTOM_ATTR_TYPE
- MONO_CUSTOM_ATTR_VALUE

DeclSecurity

MONO_TABLE_DECLSECURITY

Array size: MONO_DECL_SECURITY_SIZE

- MONO_DECL_SECURITY_ACTION
- MONO_DECL_SECURITY_PARENT
- MONO_DECL_SECURITY_PERMISSIONSET

EventMap

MONO_TABLE_EVENTMAP

Array size: MONO_EVENT_MAP_SIZE

- MONO_EVENT_MAP_PARENT
- MONO_EVENT_MAP_EVENTLIST

EventPtr

MONO_TABLE_EVENT_POINTER

Array size: MONO_EVENT_POINTER_SIZE

- MONO_EVENT_POINTER_EVENT

Event

MONO_TABLE_EVENT

Array size: MONO_EVENT_SIZE

- MONO_EVENT_FLAGS
- MONO_EVENT_NAME
- MONO_EVENT_TYPE

ExportedType

MONO_TABLE_EXPORTEDTYPE

Array size: MONO_EXPORTEDTYPE_SIZE

- MONO_EXP_TYPE_FLAGS
- MONO_EXP_TYPE_TYPEDEF
- MONO_EXP_TYPE_NAME
- MONO_EXP_TYPE_NAMESPACE
- MONO_EXP_TYPE_IMPLEMENTATION

Field

MONO_TABLE_FIELD

Array size: MONO_FIELD_SIZE

- MONO_FIELD_FLAGS
- MONO_FIELD_NAME
- MONO_FIELD_SIGNATURE

FieldLayoutt

MONO_TABLE_FIELDLAYOUT

Array size: MONO_FIELDLAYOUT_SIZE

- MONO_FIELD_LAYOUT_OFFSET
- MONO_FIELD_LAYOUT_FIELD

FieldMarshal

MONO_TABLE_FIELDMARSHAL

Array size: MONO_FIELD_MARSHAL_SIZE

- MONO_FIELD_MARSHAL_PARENT
- MONO_FIELD_MARSHAL_NATIVE_TYPE

FieldPtr

MONO_TABLE_FIELD_POINTER

Array size: MONO_FIELD_POINTER_SIZE

- MONO_FIELD_POINTER_FIELD

FieldRVA

MONO_TABLE_FIELDRVA

Array size: MONO_FIELDRVA_SIZE

- MONO_FIELD_RVA_RVA
- MONO_FIELD_RVA_FIELD

File

MONO_TABLE_FILE

Array size: MONO_FILE_SIZE

- MONO_FILE_FLAGS
- MONO_FILE_NAME
- MONO_FILE_HASH_VALUE

GenericParam

MONO_TABLE_GENERICPARAM

Array size: MONO_GENERICPARAM_SIZE

- MONO_GENERICPARAM_NUMBER
- MONO_GENERICPARAM_FLAGS
- MONO_GENERICPARAM_OWNER
- MONO_GENERICPARAM_NAME

GenericParamConstraint

MONO_TABLE_GENERICPARAMCONSTRAINT

Array size: MONO_GENERICPARAMCONSTRAINT_SIZE

- MONO_GENPARCONSTRAINT_GENERICPAR
- MONO_GENPARCONSTRAINT_CONSTRAINT

ImplMap

MONO_TABLE_IMPLMAP

Array size: MONO_IMPLMAP_SIZE

- MONO_IMPLMAP_FLAGS
- MONO_IMPLMAP_MEMBER
- MONO_IMPLMAP_NAME
- MONO_IMPLMAP_SCOPE

InterfaceImpl

MONO_TABLE_INTERFACEIMPL

Array size:
- MONO_INTERFACEIMPL_SIZE
  - MONO_INTERFACEIMPL_CLASS
  - MONO_INTERFACEIMPL_INTERFACE

ManifestResource

MONO_TABLE_MANIFESTRESOURCE

Array size: MONO_MANIFESTRESOURCE_SIZE

- MONO_MANIFEST_OFFSET
- MONO_MANIFEST_FLAGS
- MONO_MANIFEST_NAME
- MONO_MANIFEST_IMPLEMENTATION

MemberRef

MONO_TABLE_MEMBERREF

Array size: MONO_MEMBERREF_SIZE

- MONO_MEMBERREF_CLASS
- MONO_MEMBERREF_NAME
- MONO_MEMBERREF_SIGNATURE

MethodImpl

MONO_TABLE_METHODIMPL

Array size: MONO_METHODIMPL_SIZE

- MONO_METHODIMPL_CLASS
- MONO_METHODIMPL_BODY
- MONO_METHODIMPL_DECLARATION

MethodSpec

MONO_TABLE_METHODSPEC

Array size: MONO_METHODSPEC_SIZE

- MONO_METHODSPEC_METHOD
- MONO_METHODSPEC_SIGNATURE

MethodSemantics

MONO_TABLE_METHODSEMANTICS

Array size: MONO_METHOD_SEMA_SIZE

- MONO_METHOD_SEMA_SEMANTICS
- MONO_METHOD_SEMA_METHOD
- MONO_METHOD_SEMA_ASSOCIATION

Moduleref

MONO_TABLE_MODULEREF

Array size: MONO_MODULEREF_SIZE

- MONO_MODULEREF_NAME

Module

MONO_TABLE_MODULE

Array size: MONO_MODULE_SIZE
Columns:

- MONO_MODULE_GENERATION
- MONO_MODULE_NAME
- MONO_MODULE_MVID
- MONO_MODULE_ENC
- MONO_MODULE_ENCBASE

TypeRef

MONO_TABLE_TYPEREF

Array size: MONO_TYPEREF_SIZE

- MONO_TYPEREF_SCOPE
- MONO_TYPEREF_NAME
- MONO_TYPEREF_NAMESPACE

MethodPtr

MONO_TABLE_METHOD_POINTER

Array size: MONO_METHOD_POINTER_SIZE

- MONO_METHOD_POINTER_METHOD

Method

MONO_TABLE_METHOD

Array size: MONO_METHOD_SIZE

- MONO_METHOD_RVA
- MONO_METHOD_IMPLFLAGS
- MONO_METHOD_FLAGS
- MONO_METHOD_NAME
- MONO_METHOD_SIGNATURE
- MONO_METHOD_PARAMLIST

NestedClass

MONO_TABLE_NESTEDCLASS

Array size: MONO_NESTEDCLASS_SIZE

- MONO_NESTED_CLASS_NESTED
- MONO_NESTED_CLASS_ENCLOSING

ParamPtr

MONO_TABLE_PARAM_POINTER

Array size: MONO_PARAM_POINTER_SIZE

- MONO_PARAM_POINTER_PARAM

Param

MONO_TABLE_PARAM

Array size: MONO_PARAM_SIZE

- MONO_PARAM_FLAGS
- MONO_PARAM_SEQUENCE
- MONO_PARAM_NAME

PropertyMap

MONO_TABLE_PROPERTYMAP

Array size: MONO_PROPERTY_MAP_SIZE

- MONO_PROPERTY_MAP_PARENT
- MONO_PROPERTY_MAP_PROPERTY_LIST

PropertyPtr

MONO_TABLE_PROPERTY_POINTER

Array size: MONO_PROPERTY_POINTER_SIZE

- MONO_PROPERTY_POINTER_PROPERTY

Property

MONO_TABLE_PROPERTY

Array size: MONO_PROPERTY_SIZE

- MONO_PROPERTY_FLAGS
- MONO_PROPERTY_NAME
- MONO_PROPERTY_TYPE

StandaloneSig

MONO_TABLE_STANDALONESIG

Array size:
- MONO_STAND_ALONE_SIGNATURE_SIZE
  - MONO_STAND_ALONE_SIGNATURE

TypeDef

MONO_TABLE_TYPEDEF

Array size: MONO_TYPEDEF_SIZE

- MONO_TYPEDEF_FLAGS
- MONO_TYPEDEF_NAME
- MONO_TYPEDEF_NAMESPACE
- MONO_TYPEDEF_EXTENDS
- MONO_TYPEDEF_FIELD_LIST
- MONO_TYPEDEF_METHOD_LIST

TypeSpec

MONO_TABLE_TYPESPEC

Array size: MONO_TYPESPEC_SIZE

- MONO_TYPESPEC_SIGNATURE

Each table can contain zero or more rows, you must call the mono_metadata_table_rows to obtain the number of rows in a table, and then you can extract individual row values by using the mono_metadata_decode_row or the mono_metadata_decode_row_col. When decoding rows you must provide an guint32 array large enough to hold as many columns as the table contains.

The metadata tables are stored in the MonoImage, you obtain a pointer to the MonoTableInfo by calling the mono_image_get_table_info and then you can scan those tables, for example:

    	/*
    	 * Dumps a few fields from the AssemblyRef table
    	 */
    	void DumpAssemblyRefs (MonoImage *image)
    	{
    		/* Get a pointer to the AssemblyRef metadata table */
    		MonoTableInfo *t = mono_image_get_table_info (image, MONO_TABLE_ASSEMBLYREF);

    		/* Fetch the number of rows available in the table */
    		int rows = mono_table_info_get_rows (t);
    		int i;

    		/* For each row, print some of its values */
    		for (i = 0; i < rows; i++){
    			/* Space where we extract one row from the metadata table */
    			guint32 cols [MONO_ASSEMBLYREF_SIZE];

    			/* Extract the row into the array cols */
    			mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);

    			fprintf (output, "%d: Version=%d.%d.%d.%d\n\tName=%s\n", i + 1,
                            	cols [MONO_ASSEMBLYREF_MAJOR_VERSION],
                            	cols [MONO_ASSEMBLYREF_MINOR_VERSION],
                            	cols [MONO_ASSEMBLYREF_BUILD_NUMBER],
                            	cols [MONO_ASSEMBLYREF_REV_NUMBER],
                            	mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_NAME]));
    		}
    	}

The above program shows the following output when ran on the C# compiler:

    	1: Version=1.0.5000.0
    		Name=mscorlib
    	2: Version=1.0.5000.0
    		Name=System
    	3: Version=1.0.5000.0
    		Name=System.Xml

### Metadata Tables API

These are the APIs for dealing with tables:
`mono_image_get_table_info`
Syntax
const MonoTableInfo* mono_image_get_table_info (MonoImage *image, int table_id)

`mono_image_get_table_rows`
Syntax
int mono_image_get_table_rows (MonoImage *image, int table_id)

`mono_metadata_decode_row_col`
Syntax
guint32 mono_metadata_decode_row_col (const MonoTableInfo *t, int idx, guint col)

Parameters

t | table to extract information from.
idx | index for row in table.
col | column in the row.

Description

This function returns the value of column col from the idx row in the table t .
`mono_metadata_decode_row`
Syntax
void mono_metadata_decode_row (const MonoTableInfo *t, int idx, guint32 *res, int res_size)

Parameters

t | table to extract information from.
idx | index in table.
res | array of res_size cols to store the results in

Description

This decompresses the metadata element idx in table t into the `guint32` res array that has res_size elements
`mono_metadata_compute_size`
Syntax
int mono_metadata_compute_size (MonoImage *meta, int tableindex, guint32 *result_bitfield)

Parameters

meta | metadata context
tableindex | metadata table number
result_bitfield | pointer to `guint32` where to store additional info

Description

`mono_metadata_compute_size` computes the length in bytes of a single row in a metadata table. The size of each column is encoded in the result_bitfield return value along with the number of columns in the table. the resulting bitfield should be handed to the `mono_metadata_table_size` and `mono_metadata_table_count` macros. This is a Mono runtime internal only function.
`mono_metadata_custom_attrs_from_index`
Syntax
guint32 mono_metadata_custom_attrs_from_index (MonoImage *meta, guint32 index)

Parameters

meta | metadata context
index | token representing the parent
returns | the 1-based index into the `CustomAttribute` table of the first

Description
attribute which belongs to the metadata object described by index. Returns 0 if no such attribute is found.
`mono_metadata_decode_signed_value`
Syntax
gint32 mono_metadata_decode_signed_value (const char *ptr, const char **rptr)

Parameters

ptr | pointer to decode from
rptr | the new position of the pointer

Return value
the decoded value
Description

This routine decompresses 32-bit signed values (not specified in the spec)

`mono_metadata_decode_value`
Syntax
guint32 mono_metadata_decode_value (const char *_ptr, const char **rptr)

Parameters

ptr | pointer to decode from
rptr | the new position of the pointer

Return value
the decoded value
Description

This routine decompresses 32-bit values as specified in the "Blob and Signature" section (23.2)

`mono_metadata_encode_value`
Syntax
mono_metadata_encode_value

## Metadata access API

This is the low-level API for accessing the metadata images.
`mono_pe_file_open`
Syntax
MonoImage* mono_pe_file_open (const char *fname, MonoImageOpenStatus *status)

Parameters

fname | filename that points to the module we want to open
status | An error condition is returned in this field

Return value
An open image of type `MonoImage` or `NULL` on error. if `NULL`, then check the value of status for details on the error. This variant for `mono_image_open` DOES NOT SET UP CLI METADATA. It's just a PE file loader, used for `FileVersionInfo`. It also does not use the image cache.
`mono_metadata_events_from_typedef`
Syntax
guint32 mono_metadata_events_from_typedef (MonoImage *meta, guint32 index, guint *end_idx)

Parameters

meta | metadata context
index | 0-based index (in the `TypeDef` table) describing a type

Return value
the 0-based index in the `Event` table for the events in the type. The last event that belongs to the type (plus 1) is stored in the end_idx pointer.
`mono_metadata_decode_table_row`
Syntax
void mono_metadata_decode_table_row (MonoImage *image, int table, int idx, guint32 *res, int res_size)

Description

Same as `mono_metadata_decode_row`, but takes an image + table ID pair, and takes uncompressed metadata into account, so it should be used to access the `Method`, `Field`, `Param` and `Event` tables when the access is made from metadata, i.e. idx is retrieved from a metadata table, like `MONO_TYPEDEF_FIELD_LIST`.
`mono_metadata_decode_table_row_col`
Syntax
guint32 mono_metadata_decode_table_row_col (MonoImage *image, int table, int idx, guint col)

Description

Same as `mono_metadata_decode_row_col`, but takes an image + table ID pair, and takes uncompressed metadata into account, so it should be used to access the `Method`, `Field`, `Param` and `Event` tables.
`mono_metadata_field_info`
Syntax
void mono_metadata_field_info (MonoImage *meta, guint32 index, guint32 *offset, guint32 *rva, MonoMarshalSpec **marshal_spec)

Parameters

meta | the Image the field is defined in
index | the index in the field table representing the field
offset | a pointer to an integer where to store the offset that may have been specified for the field in a FieldLayout table
rva | a pointer to the RVA of the field data in the image that may have been defined in a `FieldRVA` table
marshal_spec | a pointer to the marshal spec that may have been defined for the field in a `FieldMarshal` table.

Description

Gather info for field index that may have been defined in the `FieldLayout`, `FieldRVA` and `FieldMarshal` tables. Either of offset, rva and marshal_spec can be `NULL` if you're not interested in the data.
`mono_metadata_free_array`
Syntax
void mono_metadata_free_array (MonoArrayType *array)

Parameters

array | array description

Description

Frees the array description returned from `mono_metadata_parse_array`.
`mono_metadata_free_marshal_spec`
Syntax
void mono_metadata_free_marshal_spec (MonoMarshalSpec *spec)

`mono_metadata_free_mh`
Syntax
void mono_metadata_free_mh (MonoMethodHeader *mh)

Parameters

mh | a method header

Description

Free the memory allocated for the method header.
`mono_metadata_free_type`
Syntax
void mono_metadata_free_type (MonoType *type)

Parameters

type | type to free

Description

Free the memory allocated for type type which is allocated on the heap.
`mono_metadata_get_constant_index`
Syntax
guint32 mono_metadata_get_constant_index (MonoImage *meta, guint32 token, guint32 hint)

Parameters

meta | the Image the field is defined in
index | the token that may have a row defined in the constants table
hint | possible position for the row

Return value
the index into the `Constants` table or 0 if not found.
Description

token must be a `FieldDef`, `ParamDef` or `PropertyDef` token.

`mono_metadata_get_marshal_info`
Syntax
const char* mono_metadata_get_marshal_info (MonoImage *meta, guint32 idx, gboolean is_field)

`mono_metadata_implmap_from_method`
Syntax
guint32 mono_metadata_implmap_from_method (MonoImage *meta, guint32 method_idx)

`mono_metadata_interfaces_from_typedef`
Syntax
MonoClass* mono_metadata_interfaces_from_typedef (MonoImage *meta, guint32 index, guint *count)

Parameters

meta | metadata context
index | typedef token
count | Out parameter used to store the number of interfaces

Return value
the interface array on success, `NULL` on failure.
Description

The array of interfaces that the index typedef token implements is returned in interfaces. The number of elements in the array is returned in count. The returned array is allocated with `g_malloc` and the caller must free it.

LOCKING: Acquires the loader lock .

`mono_metadata_locate`
Syntax
const char * mono_metadata_locate (MonoImage *meta, int table, int idx)

Parameters

meta | metadata context
table | table code.
idx | index of element to retrieve from table.

Return value
a pointer to the idx element in the metadata table whose code is table.
Description

`mono_metadata_locate_token`
Syntax
const char * mono_metadata_locate_token (MonoImage *meta, guint32 token)

Parameters

meta | metadata context
token | metadata token

Return value
a pointer to the data in the metadata represented by the token token .
Description

`mono_metadata_methods_from_event`
Syntax
guint32 mono_metadata_methods_from_event (MonoImage *meta, guint32 index, guint *end_idx)

Parameters

meta | metadata context
index | 0-based index (in the `Event` table) describing a event

Return value
the 0-based index in the `MethodDef` table for the methods in the event. The last method that belongs to the event (plus 1) is stored in the end_idx pointer.
`mono_metadata_methods_from_property`
Syntax
guint32 mono_metadata_methods_from_property (MonoImage *meta, guint32 index, guint *end_idx)

Parameters

meta | metadata context
index | 0-based index (in the `PropertyDef` table) describing a property

Return value
the 0-based index in the `MethodDef` table for the methods in the property. The last method that belongs to the property (plus 1) is stored in the end_idx pointer.
`mono_metadata_nested_in_typedef`
Syntax
guint32 mono_metadata_nested_in_typedef (MonoImage *meta, guint32 index)

Parameters

meta | metadata context
index | typedef token

Return value
the 1-based index into the TypeDef table of the type where the type described by index is nested. Returns 0 if index describes a non-nested type.
`mono_metadata_nesting_typedef`
Syntax
guint32 mono_metadata_nesting_typedef (MonoImage *meta, guint32 index, guint32 start_index)

Parameters

meta | metadata context
index | typedef token

Return value
the 1-based index into the `TypeDef` table of the first type that is nested inside the type described by index. The search starts at start_index. Returns 0 if no such type is found.
`mono_metadata_packing_from_typedef`
Syntax
guint32 mono_metadata_packing_from_typedef (MonoImage *meta, guint32 index, guint32 *packing, guint32 *size)

Parameters

meta | metadata context
index | token representing a type

Return value
the info stored in the `ClassLayout` table for the given typedef token into the packing and size pointers. Returns 0 if the info is not found.
`mono_metadata_properties_from_typedef`
Syntax
guint32 mono_metadata_properties_from_typedef (MonoImage *meta, guint32 index, guint *end_idx)

Parameters

meta | metadata context
index | 0-based index (in the `TypeDef` table) describing a type

Return value
the 0-based index in the `Property` table for the properties in the type. The last property that belongs to the type (plus 1) is stored in the end_idx pointer.
`mono_metadata_token_from_dor`
Syntax
guint32 mono_metadata_token_from_dor (guint32 dor_index)

Parameters

dor_token | A `TypeDefOrRef` coded index

Return value
an expanded token
Description

dor_token is a `TypeDefOrRef` coded index: it contains either a `TypeDef`, `TypeRef` or `TypeSpec` in the lower bits, and the upper bits contain an index into the table.

`mono_metadata_translate_token_index`
Syntax
guint32 mono_metadata_translate_token_index (MonoImage *image, int table, guint32 idx)

Description
Translates the given 1-based index into the `Method`, `Field`, `Event`, or `Param` tables using the `*Ptr` tables in uncompressed metadata, if they are available.

FIXME: The caller is not forced to call this function, which is error-prone, since forgetting to call it would only show up as a bug on uncompressed metadata.
`mono_metadata_typedef_from_field`
Syntax
guint32 mono_metadata_typedef_from_field (MonoImage *meta, guint32 index)

Parameters

meta | metadata context
index | FieldDef token

Return value
the 1-based index into the `TypeDef` table of the type that declared the field described by index, or 0 if not found.
Description

`mono_metadata_typedef_from_method`
Syntax
guint32 mono_metadata_typedef_from_method (MonoImage *meta, guint32 index)

Parameters

meta | metadata context
index | `MethodDef` token

Return value
the 1-based index into the `TypeDef` table of the type that declared the method described by index. 0 if not found.
`mono_metadata_type_equal`
Syntax
gboolean mono_metadata_type_equal (MonoType *t1, MonoType *t2)

`mono_metadata_type_hash`
Syntax
guint mono_metadata_type_hash (MonoType *t1)

Parameters

t1 | a type

Description
Computes a hash value for t1 to be used in `GHashTable`. The returned hash is guaranteed to be the same across executions.
`mono_metadata_declsec_from_index`
Syntax
guint32 mono_metadata_declsec_from_index (MonoImage *meta, guint32 index)

Parameters

meta | metadata context
index | token representing the parent

Return value
the 0-based index into the `DeclarativeSecurity` table of the first attribute which belongs to the metadata object described by index. Returns `-1` if no such attribute is found.
`mono_metadata_free_method_signature`
Syntax
void mono_metadata_free_method_signature (MonoMethodSignature *sig)

Parameters

sig | signature to destroy

Description

Free the memory allocated in the signature sig. This method needs to be robust and work also on partially-built signatures, so it does extra checks.

### Retrieving Objects from Tokens

`mono_metadata_parse_array`
Syntax
MonoArrayType* mono_metadata_parse_array (MonoImage *m, const char *ptr, const char **rptr)

`mono_metadata_parse_custom_mod`
Syntax
int mono_metadata_parse_custom_mod (MonoImage *m, MonoCustomMod *dest, const char *ptr, const char **rptr)

Parameters

m | a metadata context.
dest | storage where the info about the custom modifier is stored (may be `NULL`)
ptr | a pointer to (possibly) the start of a custom modifier list
rptr | pointer updated to match the end of the decoded stream

Return value
`TRUE` if a custom modifier was found, `FALSE` if not.
Description

Checks if ptr points to a type custom modifier compressed representation.

`mono_metadata_parse_field_type`
Syntax
MonoType* mono_metadata_parse_field_type (MonoImage *m, short field_flags, const char *ptr, const char **rptr)

Parameters

m | metadata context to extract information from
ptr | pointer to the field signature
rptr | pointer updated to match the end of the decoded stream

Return value
The `MonoType` that was extracted from ptr .
Description

Parses the field signature, and returns the type information for it.

`mono_metadata_parse_marshal_spec`
Syntax
MonoMarshalSpec* mono_metadata_parse_marshal_spec (MonoImage *image, const char *ptr)

`mono_metadata_parse_method_signature`
Syntax
MonoMethodSignature* mono_metadata_parse_method_signature (MonoImage *m, int def, const char *ptr, const char **rptr)

Parameters

m | metadata context
def | the `MethodDef` index or 0 for `Ref` signatures.
ptr | pointer to the signature metadata representation
rptr | pointer updated to match the end of the decoded stream

Return value
a `MonoMethodSignature` describing the signature.
Description

Decode a method signature stored at ptr. This is a Mono runtime internal function.

LOCKING: Assumes the loader lock is held.

`mono_metadata_parse_mh`
Syntax
MonoMethodHeader* mono_metadata_parse_mh (MonoImage *m, const char *ptr)

Parameters

generic_context | generics context
ptr | pointer to the method header.

Return value
a transient `MonoMethodHeader` allocated from the heap.
Description

Decode the method header at ptr, including pointer to the IL code, info about local variables and optional exception tables.

`mono_metadata_parse_param`
Syntax
MonoType* mono_metadata_parse_param (MonoImage *m, const char *ptr, const char **rptr)

Parameters

m | metadata context to extract information from
ptr | pointer to the param signature
rptr | pointer updated to match the end of the decoded stream

Return value
The `MonoType` that was extracted from ptr .
Description

Parses the param signature, and returns the type information for it.

`mono_metadata_parse_signature`
Syntax
MonoMethodSignature* mono_metadata_parse_signature (MonoImage *image, guint32 token)

Parameters

image | metadata context
token | metadata token

Return value
a `MonoMethodSignature` describing the signature.
Description

Decode a method signature stored in the `StandAloneSig` table

`mono_metadata_parse_typedef_or_ref`
Syntax
guint32 mono_metadata_parse_typedef_or_ref (MonoImage *m, const char *ptr, const char **rptr)

Parameters

m | a metadata context.
ptr | a pointer to an encoded TypedefOrRef in m
rptr | pointer updated to match the end of the decoded stream

Return value
a token valid in the m metadata decoded from the compressed representation.
`mono_metadata_parse_type`
Syntax
static MonoType* mono_metadata_parse_type_internal (MonoImage *m, MonoGenericContainer *container, short opt_attrs, gboolean transient, const char *ptr, const char **rptr, MonoError *error)

Parameters

m | metadata context
mode | kind of type that may be found at ptr
opt_attrs | optional attributes to store in the returned type
ptr | pointer to the type representation
rptr | pointer updated to match the end of the decoded stream
transient | whenever to allocate the result from the heap or from a mempool

Return value
a `MonoType` structure representing the decoded type.
Description

Decode a compressed type description found at ptr in m . mode can be one of `MONO_PARSE_MOD_TYPE`, `MONO_PARSE_PARAM`, `MONO_PARSE_RET`, `MONO_PARSE_FIELD`, `MONO_PARSE_LOCAL`, `MONO_PARSE_TYPE`. This function can be used to decode type descriptions in method signatures, field signatures, locals signatures etc.

To parse a generic type, `generic_container` points to the current class'es (the `generic_container` field in the `MonoClass`) or the current generic method's (stored in `image->property_hash`) generic container. When we encounter a `MONO_TYPE_VAR` or `MONO_TYPE_MVAR`, it's looked up in this `MonoGenericContainer`.

LOCKING: Acquires the loader lock.

## Generics Support

`mono_metadata_generic_class_is_valuetype`
Syntax
gboolean mono_metadata_generic_class_is_valuetype (MonoGenericClass *gclass)

## Tokens

`mono_ldtoken`
Syntax
gpointer mono_ldtoken (MonoImage *image, guint32 token, MonoClass **handle_class, MonoGenericContext *context)

`mono_ldstr`
Syntax
MonoString* mono_ldstr (MonoDomain *domain, MonoImage *image, guint32 idx)

Parameters

domain | the domain where the string will be used.
image | a metadata context
idx | index into the user string table.

Return value
a loaded string from the image / idx combination.
Description
Implementation for the `ldstr` opcode.
`mono_exception_from_token`
Syntax
MonoException* mono_exception_from_token (MonoImage *image, guint32 token)

Parameters

image | the Mono image where to look for the class
token | The type token of the class

Return value
the initialized exception instance.
Description

Creates an exception of the type given by token.

## OpCodes

`mono_opcode_name`
Syntax
const char* mono_opcode_name (int opcode)