The object API deals with all the operations shared by objects, value types, arrays.
The object API has methods for accessing fields, properties, events, delegates.
There are some advanced uses that are useful to document here dealing with remote fields.
MonoObject is the base definition for all managed objects in the Mono runtime, it represents the System.Object managed type.
All objects that derive from System.Object do have this base definition. Derived objects are declared following the pattern where the parent class is the first field of a structure definition, for example:
Parameters
Returnsklass: the class of the object that we want to create
a newly created object whose definition is looked up using klass. This will not invoke any constructors, so the consumer of this routine has to invoke any constructors on its own to initialize the object.It returns NULL on failure.
For example, if you wanted to create an object of type System.Version, you would use a piece of code like this:
Parameters
Returnsimage: Context where the type_token is hosted token: a token of the type that we want to create
A newly created object whose definition is looked up using token in the image image
Parameters
Returnsvtable: the vtable of the object that we want to create
A newly created object with class and domain specified by vtable
Parameters
Returnsobj: the object to clone
A newly created object who is a shallow copy of obj
Parameters
Returnsobj: object to query
the MonOClass of the object.Remarks
Parameters
Returnsobj: object to query
the MonoDomain where the object is hostedRemarks
Parameters
Remarksobj: object to operate on. method: method
Retrieves the MonoMethod that would be called on obj if obj is passed as the instance of a callvirt of method.
Parameters
Returnsobj: an object klass: a pointer to a class
obj if obj is derived from klass
Parameters
Returnsobj: object to unbox
a pointer to the start of the valuetype boxed in this object. This method will assert if the object passed is not a valuetype.Remarks
Parameters
Returnsobj: an object klass: a pointer to a class
obj if obj is derived from klass, throws an exception otherwise
Parameters
Returnso: object to query
the size, in bytes, of oRemarks
Parameters
Returnsclass: the class of the value value: a pointer to the unboxed data
A newly created object which contains value.
Use the mono_array_new_* methods to create arrays of a given type.
For example, the following code creates an array with two elements of type System.Byte, and sets the values 0xca and 0xfe on it:
MonoArray *CreateByteArray (MonoDomain *domain) { MonoArray *data; data = mono_array_new (domain, mono_get_byte_class (), 2); mono_array_set (data, guint8, 0, 0xca); mono_array_set (data, guint8, 0, 0xfe); return data; }
Parameters
Remarksdomain: domain where the object is created eclass: element class n: number of array elements
This routine creates a new szarray with n elements of type eclass.
Parameters
Remarksdomain: domain where the object is created array_class: array class lengths: lengths for each dimension in the array lower_bounds: lower bounds for each dimension in the array (may be NULL)
This routine creates a new array objects with the given dimensions, lower bounds and type.
Parameters
Remarksvtable: a vtable in the appropriate domain for an initialized class n: number of array elements
This routine is a fast alternative to mono_array_new() for code which can be sure about the domain it operates in.
Parameters
Returnselement_class: element class rank: the dimension of the array class
a class object describing the array with element type element_type and dimension rank.
Parameters
Returnsarray: the array to clone
A newly created array who is a shallow copy of array
Parameters
Remarksarray: a MonoArray*
Returns the total number of elements in the array. This works for both vectors and multidimensional arrays.
Parameters
Remarksarray: a MonoArray* size: size of the array elements idx: index into the array
Returns the address of the idx element in the array.
Parameters
Returnsac: pointer to a #MonoArrayClass
the size of single array element.
Parameters
Returnsfield: the MonoClassField to act on
the name of the field.
Parameters
Returnsfield: the MonoClassField to act on
MonoClass where the field was defined.
Parameters
Returnsfield: the MonoClassField to act on
MonoType of the field.
Parameters
Remarksobj: Object instance field: MonoClassField describing the field to fetch information from value: pointer to the location where the value will be stored
Use this routine to get the value of the field field in the object passed. The pointer provided by value must be of the field type, for reference types this is a MonoObject*, for value types its the actual pointer to the value type. For example: int i; mono_field_get_value (obj, int_field, &i);
Parameters
Returnsdomain: domain where the object will be created (if boxing) field: MonoClassField describing the field to fetch information from obj: The object instance for the field.
a new MonoObject with the value from the given field. If the field represents a value type, the value is boxed.
Parameters
Remarksobj: Instance object field: MonoClassField describing the field to set value: The value to be set
Sets the value of the field described by field in the object instance obj to the value passed in value. This method should only be used for instance fields. For static fields, use mono_field_static_set_value. The value must be on the native format of the field type.
Parameters
Remarksvt: vtable to the object field: MonoClassField describing the field to fetch information from value: where the value is returned
Use this routine to get the value of the static field field value. The pointer provided by value must be of the field type, for reference types this is a MonoObject*, for value types its the actual pointer to the value type. For example: int i; mono_field_static_get_value (vt, int_field, &i);
Parameters
Remarksfield: MonoClassField describing the field to set value: The value to be set
Sets the value of the static field described by field to the value passed in value. The value must be on the native format of the field type.
Parameters
Returnsprop: the MonoProperty to act on.
the flags for the property.Remarks
The metadata flags for a property are encoded using the PROPERTY_ATTRIBUTE_* constants. See the tabledefs.h file for details.
Parameters
Returnsprop: the MonoProperty to act on.
the setter method of the property (A MonoMethod)
Parameters
Returnsprop: the MonoProperty to act on.
the MonoClass where the property was defined.
Parameters
Returnsprop: the MonoProperty to act on.
the setter method of the property (A MonoMethod)
Parameters
Returnsprop: MonoProperty to fetch obj: instance object on which to act params: parameters to pass to the propery exc: optional exception
the value from invoking the get method on the property.Remarks
Invokes the property's get method with the given arguments on the object instance obj (or NULL for static properties).
You can pass NULL as the exc argument if you don't want to catch exceptions, otherwise, *exc will be set to the exception thrown, if any. if an exception is thrown, you can't use the MonoObject* result from the function.
Parameters
Remarksprop: MonoProperty to set obj: instance object on which to act params: parameters to pass to the propery exc: optional exception
Invokes the property's set method with the given arguments on the object instance obj (or NULL for static properties).
You can pass NULL as the exc argument if you don't want to catch exceptions, otherwise, *exc will be set to the exception thrown, if any. if an exception is thrown, you can't use the MonoObject* result from the function.
Parameters
Returnsevent: The MonoEvent to act on.
the add' method for the event (a MonoMethod).
Parameters
Returnsevent: the MonoEvent to act on.
the flags for the event.Remarks
The metadata flags for an event are encoded using the EVENT_* constants. See the tabledefs.h file for details.
Parameters
Returnsevent: the MonoEvent to act on
the name of the event.
Parameters
Returnsevent: the MonoEvent to act on.
the MonoClass where the event is defined.
Parameters
Returnsevent: The MonoEvent to act on.
the raise method for the event (a MonoMethod).
Parameters
Returnsevent: The MonoEvent to act on.
the remove method for the event (a MonoMethod).
Parameters
Returnsthis: pointer to an object klass: klass of the object containing field field: the field to load res: a storage to store the result
an address pointing to the value of field.Remarks
This method is called by the runtime on attempts to load fields of transparent proxy objects. this points to such TP, klass is the class of the object containing field. res is a storage location which can be used to store the result.
Parameters
Remarksthis: klass: field:
Missing documentation.
Parameters
Remarksthis: pointer to an object klass: klass of the object containing field field: the field to load val: the value/object to store
This method is called by the runtime on attempts to store fields of transparent proxy objects. this points to such TP, klass is the class of the object containing field. val is the new value to store in field.