mono-api-object.html 7.9 KB

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