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

source

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.

source

pub fn get_ptr(&self) -> *mut MonoClassField

Gets internal [MonoClassField] pointer.

source

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);
source

pub fn get_data(&self) -> *const c_char

Gets metadata(???) tokens of a field. not it’s value

source

pub fn get_parent(&self) -> Class

Returns Class this field is attached to.

Example
 let some_field_name = "Delimeter";
 let some_field = some_class.get_field_from_name(some_field_name).expect("Could not find field!");
 let some_field_class = some_field.get_parent();
 assert!(some_field_class == some_class);
source

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>();
source

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

source

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.

source

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.

source

pub fn set_value_object(&self, obj: &Object, value: &Object)

Sets value of field self on object to value

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.