Struct hao::dotnet::Module

source ·
pub struct Module { /* private fields */ }
Expand description

Represents a loaded .net module.

let module = Module::from_file(r#"Example.Net.dll"#);

for ty in module.types().values() {
   for method in ty.methods().values() {
       println!("{}", method.name());
   }
}

Implementations§

source§

impl Module

source

pub fn from_path(path: impl AsRef<Path>) -> Result<Self>

Load a .net assembly from the given path and resolve its dependancies with the default PathAssemblyResolver resolver.

let module = Module::from_path(r#"Example.Net.dll"#)?;
Examples found in repository?
examples/load_module.rs (line 4)
3
4
5
6
fn main() {
    let module = Module::from_path(r#"C:\re\dnspy\bin\dnlib.dll"#).unwrap();
    println!("loaded {}", module.module().value().name());
}
More examples
Hide additional examples
examples/simple.rs (line 4)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    let module = Module::from_path(r#"C:\re\dnspy\bin\dnlib.dll"#).unwrap();
    println!("loaded");

    for ty in module.types().values() {
        println!("{} {{", ty);
        if ty.is_enum() {
            for field in ty
                .fields()
                .values()
                .filter(|x| !x.flags().contains(FieldFlags::SpecialName))
            {
                println!("\t{},", field.name());
            }
        } else {
            for field in ty.fields().values() {
                println!("\t{};", field);
            }
        }

        println!("\n");

        for method in ty.methods().values() {
            println!("\t{};", method);
        }

        println!("}}");
    }
}
source

pub fn from_path_no_resolve(path: impl AsRef<Path>) -> Result<Self>

Load a .net assembly from the given path but do not reolve its dependancies.

let module = Module::from_path_no_resolve(r#"Example.Net.dll"#)?;
source

pub fn from_metadata(metadada: &Metadata<'_>) -> Result<Self>

Load a .net assembly from metadata. This will not resolve the modules dependancies.

let data = std::fs::read("Example.Net.dll").unwrap();
let md = Metadata::parse(&data).unwrap();
let loaded_module = Module::from_metadata(&md).unwrap();
source

pub fn load_dependancies( &self, resolver: &mut impl AssemblyResolver ) -> Result<()>

Attempts to load the refrenced assemblies using the given resolver. This will panic if there is a refrence holding any of the AssemblyRef in this module.

source

pub fn module(&self) -> EntryView<'_, ModuleDef>

Returns the module infomation of the current module as a EntryView.

Examples found in repository?
examples/load_module.rs (line 5)
3
4
5
6
fn main() {
    let module = Module::from_path(r#"C:\re\dnspy\bin\dnlib.dll"#).unwrap();
    println!("loaded {}", module.module().value().name());
}
source

pub fn type_refs(&self) -> EntryCollection<'_, TypeRef>

Returns an EntryCollection of TypeRef with all the type refrences inside the current module.

source

pub fn types(&self) -> EntryCollection<'_, TypeDef>

Returns all the type refrences inside the current module.

let module = Module::default();

for ty in module.types().values() {
    println!("{}", ty);
}
Examples found in repository?
examples/simple.rs (line 7)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    let module = Module::from_path(r#"C:\re\dnspy\bin\dnlib.dll"#).unwrap();
    println!("loaded");

    for ty in module.types().values() {
        println!("{} {{", ty);
        if ty.is_enum() {
            for field in ty
                .fields()
                .values()
                .filter(|x| !x.flags().contains(FieldFlags::SpecialName))
            {
                println!("\t{},", field.name());
            }
        } else {
            for field in ty.fields().values() {
                println!("\t{};", field);
            }
        }

        println!("\n");

        for method in ty.methods().values() {
            println!("\t{};", method);
        }

        println!("}}");
    }
}
source

pub fn all_fields(&self) -> EntryCollection<'_, Field>

Returns all the fields defined in the module regardless of the parent type.

If you want the associated type, use TypeDef::fields.

let module = Module::default();

for field in module.all_fields().values() {
    println!("{} {}", field.signature(), field.name());
}
source

pub fn all_methods(&self) -> EntryCollection<'_, Method>

Returns all the methods defined in the module regardless of the parent type.

If you want the associated type, use TypeDef::methods.

let module = Module::default();

for method in module.all_methods().values() {
   println!("{}", method.name());
}
source

pub fn all_params(&self) -> EntryCollection<'_, Param>

Returns all the parameters defined in the module regardless of the parent method.

If you want the associated method, use Method::params.

let module = Module::default();

for param in module.all_params().values() {
    println!("{}", param.name());
}
source

pub fn all_type_specs(&self) -> EntryCollection<'_, TypeSpec>

Returns all the type specs defined in the module.

source

pub fn module_ref(&self) -> EntryCollection<'_, ModuleRef>

Returns all the modules refrenced in the module.

source

pub fn assembly_ref(&self) -> EntryCollection<'_, AssemblyRef>

Returns all the assemblies refrenced in the module.

Trait Implementations§

source§

impl Clone for Module

source§

fn clone(&self) -> Module

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Module

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Module

source§

fn default() -> Module

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Module

§

impl !Send for Module

§

impl !Sync for Module

§

impl Unpin for Module

§

impl !UnwindSafe for Module

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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.