mono_rt/types/object.rs
1use super::{MonoClass, mono_handle};
2use crate::{Result, api};
3
4mono_handle!(MonoObject);
5
6impl MonoObject {
7 /// Returns the `MonoClass` of this object.
8 ///
9 /// Primarily useful for identifying exception types after a failed method invocation.
10 ///
11 /// # Errors
12 ///
13 /// Returns [`crate::MonoError::Uninitialized`] if the Mono API has not been initialized.
14 pub fn get_class(self) -> Result<Option<MonoClass>> {
15 let ptr = api()?.object_get_class(self.as_ptr());
16 Ok(MonoClass::from_ptr(ptr))
17 }
18
19 /// Unboxes this object and returns a raw pointer to its value-type data.
20 ///
21 /// # Errors
22 ///
23 /// Returns [`crate::MonoError::Uninitialized`] if the Mono API has not been initialized.
24 pub fn unbox(self) -> Result<*mut c_void> {
25 Ok(api()?.object_unbox(self.as_ptr()))
26 }
27}