1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
<h1>Object API</h1>
<p>The object API deals with all the operations shared by
<a href="#objects">objects</a>, <a href="#valuetypes">value
types</a>, <a href="#arrays">arrays</a>.
<p>The object API has methods for accessing <a
href="#fields">fields</a>, <a
href="#properties">properties</a>, <a href="mono-api-methods.html">methods</a>, <a
href="#events">events</a>, <a href="#delegates">delegates</a>.
<p>There are some advanced uses that are useful to document
here dealing with <a href="#remote">remote fields</a>.
<h2>Synopsis</h2>
<div class="mapi-header">
#include <metadata/object.h>
typedef struct MonoVTable MonoVTable;
typedef struct _MonoThreadsSync MonoThreadsSync;
typedef struct {
MonoVTable *vtable;
MonoThreadsSync *synchronisation;
} MonoObject;
typedef struct {
guint32 length;
guint32 lower_bound;
} MonoArrayBounds;
typedef struct {
MonoObject obj;
/* bounds is NULL for szarrays */
MonoArrayBounds *bounds;
/* total number of elements of the array */
guint32 max_length;
/* we use double to ensure proper alignment on platforms that need it */
double vector [MONO_ZERO_LEN_ARRAY];
} MonoArray;
@API_IDX@
</div>
<p>`MonoObject` is the base definition for all managed objects
in the Mono runtime, it represents the <a
href="http://www.mono-project.com/monodoc/T:System.Object">System.Object</a>
managed type.
<p>All objects that derive from <a
href="http://www.mono-project.com/monodoc/T:System.Object">System.Object</a>
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:
<div class="mapi-code">
typedef struct {
MonoObject parent;
int my_new_field;
} MyNewObject</div>
<a name="objects"></a>
<h2>Core Object Methods</h2>
<h4><a name="api:mono_object_new">mono_object_new</a></h4>
<p>For example, if you wanted to create an object of type
System.Version, you would use a piece of code like this:
<div class="mapi-code">
MonoClass *version_class;
MonoObject *result;
/* Get the class from mscorlib */
version_class = mono_class_from_name (mono_get_corlib (),
"System", "Version");
/* Create an object of that class */
result = mono_object_new (mono_domain_get (), version_class);
</div>
<h4><a name="api:mono_object_new_alloc_specific">mono_object_new_alloc_specific</a></h4>
<h4><a name="api:mono_object_new_fast">mono_object_new_fast</a></h4>
<h4><a name="api:mono_object_new_from_token">mono_object_new_from_token</a></h4>
<h4><a name="api:mono_object_new_specific">mono_object_new_specific</a></h4>
<h4><a name="api:mono_object_clone">mono_object_clone</a></h4>
<h4><a name="api:mono_object_get_class">mono_object_get_class</a></h4>
<h4><a name="api:mono_object_get_domain">mono_object_get_domain</a></h4>
<h4><a name="api:mono_object_get_virtual_method">mono_object_get_virtual_method</a></h4>
<h4><a name="api:mono_object_isinst_mbyref">mono_object_isinst_mbyref</a></h4>
<h4><a name="api:mono_object_isinst">mono_object_isinst</a></h4>
<h4><a name="api:mono_object_unbox">mono_object_unbox</a></h4>
<h4><a name="api:mono_object_castclass_mbyref">mono_object_castclass_mbyref</a></h4>
<h4><a name="api:mono_object_get_size">mono_object_get_size</a></h4>
<h4><a name="api:mono_object_hash">mono_object_hash</a></h4>
<h4><a name="api:mono_object_to_string">mono_object_to_string</a></h4>
<a name="valuetypes"></a>
<h2>Value Types</h2>
<h4><a name="api:mono_value_box">mono_value_box</a></h4>
<h4><a name="api:mono_value_copy">mono_value_copy</a></h4>
<h4><a name="api:mono_value_copy_array">mono_value_copy_array</a></h4>
<a name="arrays"></a>
<h2>Array Methods</h2>
<p>Use the <tt>mono_array_new_*</tt> methods to create arrays
of a given type.
<p>For example, the following code creates an array with two
elements of type <tt>System.Byte</tt>, and sets the values
0xca and 0xfe on it:
<pre class="mapi-code">
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;
}
</pre>
<h3>Creating Arrays</h3>
<h4><a name="api:mono_array_new">mono_array_new</a></h4>
<h4><a name="api:mono_array_new_full">mono_array_new_full</a></h4>
<h4><a name="api:mono_array_new_specific">mono_array_new_specific</a></h4>
<h4><a name="api:mono_array_class_get">mono_array_class_get</a></h4>
<h4><a name="api:mono_array_clone">mono_array_clone</a></h4>
<h3>Using Arrays</h3>
<p>Arrays are represented by the `MonoArray` data type and are
instances of `MonoObject`. While you can use the `bounds`
and `max_length` fields of the type, the actual storage
(represented by `vector`) is not very useful. Instead you
should use one of the accesor methods described below to
fetch or set the values in the array.
<p>When setting values in an array, you should
use <a href="api:mono_array_set">mono_array_set</a> for
setting elements in an array that contains value types, and
<a
href="api:mono_array_setref">mono_array_setref</a> for arrays
that contain reference types.
<p>The <a href="api:mono_array_get">mono_array_get</a>,
<a href="api:mono_array_set">mono_array_set</a> and <a
href="api:mono_array_setref">mono_array_setref</a> are C
macros that wrap the underlying array access.
<h4><a name="api:mono_array_get">mono_array_get</a></h4>
<h4><a name="api:mono_array_length">mono_array_length</a></h4>
<h4><a name="api:mono_array_set">mono_array_set</a></h4>
<h4><a name="api:mono_array_setref">mono_array_setref</a></h4>
<h4><a name="api:mono_array_addr">mono_array_addr</a></h4>
<h4><a name="api:mono_array_addr_with_size">mono_array_addr_with_size</a></h4>
<h4><a name="api:mono_array_element_size">mono_array_element_size</a></h4>
<a name="fields"></a>
<h2>Fields</h2>
<h4><a name="api:mono_field_from_token">mono_field_from_token</a></h4>
<h4><a name="api:mono_field_get_flags">mono_field_get_flags</a></h4>
<h4><a name="api:mono_field_get_name">mono_field_get_name</a></h4>
<h4><a name="api:mono_field_get_parent">mono_field_get_parent</a></h4>
<h4><a name="api:mono_field_get_type">mono_field_get_type</a></h4>
<h4><a name="api:mono_field_get_value">mono_field_get_value</a></h4>
<h4><a name="api:mono_field_get_value_object">mono_field_get_value_object</a></h4>
<h4><a name="api:mono_field_set_value">mono_field_set_value</a></h4>
<h4><a name="api:mono_field_static_get_value">mono_field_static_get_value</a></h4>
<h4><a name="api:mono_field_static_set_value">mono_field_static_set_value</a></h4>
<h4><a name="api:mono_field_get_object">mono_field_get_object</a></h4>
<a name="properties"></a>
<h2>Properties</h2>
<h4><a name="api:mono_property_get_object">mono_property_get_object</a></h4>
<h4><a name="api:mono_property_get_flags">mono_property_get_flags</a></h4>
<h4><a name="api:mono_property_get_get_method">mono_property_get_get_method</a></h4>
<h4><a name="api:mono_property_get_name">mono_property_get_name</a></h4>
<h4><a name="api:mono_property_get_parent">mono_property_get_parent</a></h4>
<h4><a name="api:mono_property_get_set_method">mono_property_get_set_method</a></h4>
<h4><a name="api:mono_property_get_value">mono_property_get_value</a></h4>
<h4><a name="api:mono_property_set_value">mono_property_set_value</a></h4>
<a name="events"></a>
<h2>Events</h2>
<h4><a name="api:mono_event_get_object">mono_event_get_object</a></h4>
<h4><a name="api:mono_event_get_add_method">mono_event_get_add_method</a></h4>
<h4><a name="api:mono_event_get_flags">mono_event_get_flags</a></h4>
<h4><a name="api:mono_event_get_name">mono_event_get_name</a></h4>
<h4><a name="api:mono_event_get_parent">mono_event_get_parent</a></h4>
<h4><a name="api:mono_event_get_raise_method">mono_event_get_raise_method</a></h4>
<h4><a name="api:mono_event_get_remove_method">mono_event_get_remove_method</a></h4>
<a name="remote"></a>
<h2>Remote Fields</h2>
<h4><a name="api:mono_load_remote_field">mono_load_remote_field</a></h4>
<h4><a name="api:mono_load_remote_field_new">mono_load_remote_field_new</a></h4>
<h4><a name="api:mono_store_remote_field">mono_store_remote_field</a></h4>
<h4><a name="api:mono_store_remote_field_new">mono_store_remote_field_new</a></h4>
<a name="delegates"></a>
<h2>Delegates</h2>
<h4><a name="api:mono_get_delegate_begin_invoke">mono_get_delegate_begin_invoke</a></h4>
<h4><a name="api:mono_get_delegate_end_invoke">mono_get_delegate_end_invoke</a></h4>
|