...and they also need EXTRA_DISTFILES for tarballs.
[mono-project.git] / docs / sources / mono-api-object.html
blob5619040698aa3bf6f9816faf721a80bf86bc3e8e
1 <h1>Object API</h1>
3 <p>The object API deals with all the operations shared by
4 <a href="#objects">objects</a>, <a href="#valuetypes">value
5 types</a>, <a href="#arrays">arrays</a>.
7 <p>The object API has methods for accessing <a
8 href="#fields">fields</a>, <a
9 href="#properties">properties</a>, <a
10 href="#events">events</a>, <a href="#delegates">delegates</a>.
12 <p>There are some advanced uses that are useful to document
13 here dealing with <a href="#remote">remote fields</a>.
15 <h2>Synopsis</h2>
17 <div class="header">
18 #include &lt;metadata/object.h&gt;
20 typedef struct MonoVTable MonoVTable;
21 typedef struct _MonoThreadsSync MonoThreadsSync;
23 typedef struct {
24 MonoVTable *vtable;
25 MonoThreadsSync *synchronisation;
26 } MonoObject;
28 typedef struct {
29 guint32 length;
30 guint32 lower_bound;
31 } MonoArrayBounds;
33 typedef struct {
34 MonoObject obj;
35 /* bounds is NULL for szarrays */
36 MonoArrayBounds *bounds;
37 /* total number of elements of the array */
38 guint32 max_length;
39 /* we use double to ensure proper alignment on platforms that need it */
40 double vector [MONO_ZERO_LEN_ARRAY];
41 } MonoArray;
43 @API_IDX@
44 </div>
46 <p>MonoObject is the base definition for all managed objects
47 in the Mono runtime, it represents the <a
48 href="http://www.mono-project.com/monodoc/T:System.Object">System.Object</a>
49 managed type.
51 <p>All objects that derive from <a
52 href="http://www.mono-project.com/monodoc/T:System.Object">System.Object</a>
53 do have this base definition. Derived objects are declared
54 following the pattern where the parent class is the first
55 field of a structure definition, for example:
57 <div class="code">
58 typedef struct {
59 MonoObject parent;
60 int my_new_field;
61 } MyNewObject
62 </div>
64 <a name="objects"></a>
65 <h2>Core Object Methods</h2>
67 <h4><a name="api:mono_object_new">mono_object_new</a></h4>
69 <p>For example, if you wanted to create an object of type
70 System.Version, you would use a piece of code like this:
72 <div class="code">
73 MonoClass *version_class;
74 MonoObject *result;
76 /* Get the class from mscorlib */
77 version_class = mono_class_from_name (mono_get_corlib (),
78 "System", "Version");
80 /* Create an object of that class */
81 result = mono_object_new (mono_domain_get (), version_class);
82 </div>
84 <h4><a name="api:mono_object_new_alloc_specific">mono_object_new_alloc_specific</a></h4>
85 <h4><a name="api:mono_object_new_fast">mono_object_new_fast</a></h4>
86 <h4><a name="api:mono_object_new_from_token">mono_object_new_from_token</a></h4>
87 <h4><a name="api:mono_object_new_specific">mono_object_new_specific</a></h4>
88 <h4><a name="api:mono_object_clone">mono_object_clone</a></h4>
89 <h4><a name="api:mono_object_get_class">mono_object_get_class</a></h4>
90 <h4><a name="api:mono_object_get_domain">mono_object_get_domain</a></h4>
91 <h4><a name="api:mono_object_get_virtual_method">mono_object_get_virtual_method</a></h4>
92 <h4><a name="api:mono_object_isinst_mbyref">mono_object_isinst_mbyref</a></h4>
93 <h4><a name="api:mono_object_isinst">mono_object_isinst</a></h4>
94 <h4><a name="api:mono_object_unbox">mono_object_unbox</a></h4>
95 <h4><a name="api:mono_object_castclass_mbyref">mono_object_castclass_mbyref</a></h4>
96 <h4><a name="api:mono_object_is_alive">mono_object_is_alive</a></h4>
97 <h4><a name="api:mono_object_get_size">mono_object_get_size</a></h4>
99 <a name="valuetypes"></a>
100 <h2>Value Types</h2>
102 <h4><a name="api:mono_value_box">mono_value_box</a></h4>
103 <h4><a name="api:mono_value_copy">mono_value_copy</a></h4>
104 <h4><a name="api:mono_value_copy_array">mono_value_copy_array</a></h4>
106 <a name="arrays"></a>
107 <h2>Array Methods</h2>
109 <p>Use the <tt>mono_array_new_*</tt> methods to create arrays
110 of a given type.
112 <p>For example, the following code creates an array with two
113 elements of type <tt>System.Byte</tt>, and sets the values
114 0xca and 0xfe on it:
116 <pre class="code">
118 MonoArray *CreateByteArray (MonoDomain *domain)
120 MonoArray *data;
122 data = mono_array_new (domain, mono_get_byte_class (), 2);
123 mono_array_set (data, guint8, 0, 0xca);
124 mono_array_set (data, guint8, 0, 0xfe);
126 return data;
129 </pre>
131 <h3>Creating Arrays</h3>
133 <h4><a name="api:mono_array_new">mono_array_new</a></h4>
134 <h4><a name="api:mono_array_new_full">mono_array_new_full</a></h4>
135 <h4><a name="api:mono_array_new_specific">mono_array_new_specific</a></h4>
136 <h4><a name="api:mono_array_class_get">mono_array_class_get</a></h4>
137 <h4><a name="api:mono_array_clone">mono_array_clone</a></h4>
139 <h3>Using Arrays</h3>
141 <h4><a name="api:mono_array_set">mono_array_set</a></h4>
142 <h4><a name="api:mono_array_setref">mono_array_setref</a></h4>
143 <h4><a name="api:mono_array_length">mono_array_length</a></h4>
144 <h4><a name="api:mono_array_addr">mono_array_addr</a></h4>
145 <h4><a name="api:mono_array_addr_with_size">mono_array_addr_with_size</a></h4>
146 <h4><a name="api:mono_array_get">mono_array_get</a></h4>
147 <h4><a name="api:mono_array_element_size">mono_array_element_size</a></h4>
149 <a name="fields"></a>
150 <h2>Fields</h2>
152 <h4><a name="api:mono_field_from_token">mono_field_from_token</a></h4>
153 <h4><a name="api:mono_field_get_flags">mono_field_get_flags</a></h4>
154 <h4><a name="api:mono_field_get_name">mono_field_get_name</a></h4>
155 <h4><a name="api:mono_field_get_parent">mono_field_get_parent</a></h4>
156 <h4><a name="api:mono_field_get_type">mono_field_get_type</a></h4>
157 <h4><a name="api:mono_field_get_value">mono_field_get_value</a></h4>
158 <h4><a name="api:mono_field_get_value_object">mono_field_get_value_object</a></h4>
159 <h4><a name="api:mono_field_set_value">mono_field_set_value</a></h4>
160 <h4><a name="api:mono_field_static_get_value">mono_field_static_get_value</a></h4>
161 <h4><a name="api:mono_field_static_set_value">mono_field_static_set_value</a></h4>
162 <h4><a name="api:mono_field_get_object">mono_field_get_object</a></h4>
164 <a name="properties"></a>
165 <h2>Properties</h2>
167 <h4><a name="api:mono_property_get_object">mono_property_get_object</a></h4>
168 <h4><a name="api:mono_property_get_flags">mono_property_get_flags</a></h4>
169 <h4><a name="api:mono_property_get_get_method">mono_property_get_get_method</a></h4>
170 <h4><a name="api:mono_property_get_name">mono_property_get_name</a></h4>
171 <h4><a name="api:mono_property_get_parent">mono_property_get_parent</a></h4>
172 <h4><a name="api:mono_property_get_set_method">mono_property_get_set_method</a></h4>
173 <h4><a name="api:mono_property_get_value">mono_property_get_value</a></h4>
174 <h4><a name="api:mono_property_set_value">mono_property_set_value</a></h4>
176 <a name="events"></a>
177 <h2>Events</h2>
179 <h4><a name="api:mono_event_get_object">mono_event_get_object</a></h4>
180 <h4><a name="api:mono_event_get_add_method">mono_event_get_add_method</a></h4>
181 <h4><a name="api:mono_event_get_flags">mono_event_get_flags</a></h4>
182 <h4><a name="api:mono_event_get_name">mono_event_get_name</a></h4>
183 <h4><a name="api:mono_event_get_parent">mono_event_get_parent</a></h4>
184 <h4><a name="api:mono_event_get_raise_method">mono_event_get_raise_method</a></h4>
185 <h4><a name="api:mono_event_get_remove_method">mono_event_get_remove_method</a></h4>
187 <a name="remote"></a>
188 <h2>Remote Fields</h2>
189 <h4><a name="api:mono_load_remote_field">mono_load_remote_field</a></h4>
190 <h4><a name="api:mono_load_remote_field_new">mono_load_remote_field_new</a></h4>
191 <h4><a name="api:mono_store_remote_field">mono_store_remote_field</a></h4>
192 <h4><a name="api:mono_store_remote_field_new">mono_store_remote_field_new</a></h4>