Struct wrapped_mono::ClassField
source · pub struct ClassField { /* private fields */ }
Expand description
Representation of a class field. Accessors(getters,setters and indexers) are not fields, but properties! For them use ClassProperity
Implementations§
source§impl ClassField
impl ClassField
sourcepub unsafe fn from_ptr(cf_ptr: *mut MonoClassField) -> Option<Self>
pub unsafe fn from_ptr(cf_ptr: *mut MonoClassField) -> Option<Self>
Creates ClassField
form cf_ptr
. Returns [Some(ClassField)
] if pointer is not null, and None
if it is.
Safety
cf_ptr
must be either a valid pointer to [MonoClassField
] or null pointer.
sourcepub fn get_name(&self) -> String
pub fn get_name(&self) -> String
Gets the name of ClassField
Example
let some_field_name = "Delimeter";
let some_field = some_class.get_field_from_name(some_field_name).expect("Could not find field!");
let name = some_field.get_name();
assert!(some_field_name == name);
sourcepub fn get_parent(&self) -> Class
pub fn get_parent(&self) -> Class
sourcepub fn get_value_object(&self, obj: &Object) -> Option<Object>
pub fn get_value_object(&self, obj: &Object) -> Option<Object>
Gets value of a field on Object
obj. For boxable types this value is in boxed form.
In this case call Object
.unbox() to retrieve pointer to unboxed version of this value.
Example
C#
class SomeClass{
int someField;
}
Rust
# use wrapped_mono::*;
let some_field_value_object = some_field.get_value_object(&instance_of_some_class);
// Retrived value *some_field_value_object* is a boxed int, so we must unbox it.
let some_field_value = some_field_value_object.unbox::<i32>();
sourcepub unsafe fn set_value_unsafe(&self, obj: &Object, value_ptr: *mut c_void)
pub unsafe fn set_value_unsafe(&self, obj: &Object, value_ptr: *mut c_void)
Sets value of the object field on Object
to value pointed to by value_ptr
Example
C#
class SomeClass{
int someField;
}
Rust
# use wrapped_mono::*;
# let some_image = Assembly::assembly_loaded("mscorlib").expect("Assembly mscorlib not loaded, could not get System.Type class!").get_image();
# let some_class = Class::from_name_case(&some_image,"System","Type").expect("Could not find a class!");
let some_field = some_class.get_field_from_name("Delimiter").expect("Could not find field!");
let value_to_set:u16 = 11;
let some_field_value_object = some_field.set_value_unsafe(&instance_of_some_class,&mut value_to_set as *mut u16 as *mut std::os::raw::c_void);
Safety
value_ptr
pointer must be valid and have correct type.
source§impl ClassField
impl ClassField
sourcepub fn set_value<T: InteropBox>(
&self,
obj: &Object,
val: T
) -> Result<(), String>
pub fn set_value<T: InteropBox>( &self, obj: &Object, val: T ) -> Result<(), String>
Sets value of a boxable type. WARING: currently there are no checks to ensure value type and field type match.
Errors
Returns error message if failed.
sourcepub fn get_value<T: InteropBox + Copy + InteropClass>(
&self,
obj: &Object
) -> Result<T, String>
pub fn get_value<T: InteropBox + Copy + InteropClass>( &self, obj: &Object ) -> Result<T, String>
Gets value of a boxable type. Returns unboxed value or error message if unboxing failed.
Errors
Returns error message if failed.
sourcepub fn set_value_object(&self, obj: &Object, value: &Object)
pub fn set_value_object(&self, obj: &Object, value: &Object)
Sets value of field self on object to value