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
impl Module
Sourcepub fn from_path(path: impl AsRef<Path>) -> Result<Self>
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?
More examples
3fn main() {
4 let module = Module::from_path(r#"C:\re\dnspy\bin\dnlib.dll"#).unwrap();
5 println!("loaded");
6
7 for ty in module.types().values() {
8 println!("{} {{", ty);
9 if ty.is_enum() {
10 for field in ty
11 .fields()
12 .values()
13 .filter(|x| !x.flags().contains(FieldFlags::SpecialName))
14 {
15 println!("\t{},", field.name());
16 }
17 } else {
18 for field in ty.fields().values() {
19 println!("\t{};", field);
20 }
21 }
22
23 println!("\n");
24
25 for method in ty.methods().values() {
26 println!("\t{};", method);
27 }
28
29 println!("}}");
30 }
31}
Sourcepub fn from_path_no_resolve(path: impl AsRef<Path>) -> Result<Self>
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"#)?;
Sourcepub fn from_metadata(metadada: &Metadata<'_>) -> Result<Self>
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();
Sourcepub fn load_dependancies(
&self,
resolver: &mut impl AssemblyResolver,
) -> Result<()>
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.
Sourcepub fn module(&self) -> EntryView<'_, ModuleDef>
pub fn module(&self) -> EntryView<'_, ModuleDef>
Returns the module infomation of the current module as a EntryView
.
Sourcepub fn type_refs(&self) -> EntryCollection<'_, TypeRef> ⓘ
pub fn type_refs(&self) -> EntryCollection<'_, TypeRef> ⓘ
Returns an EntryCollection
of TypeRef
with all the type refrences
inside the current module.
Sourcepub fn types(&self) -> EntryCollection<'_, TypeDef> ⓘ
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?
3fn main() {
4 let module = Module::from_path(r#"C:\re\dnspy\bin\dnlib.dll"#).unwrap();
5 println!("loaded");
6
7 for ty in module.types().values() {
8 println!("{} {{", ty);
9 if ty.is_enum() {
10 for field in ty
11 .fields()
12 .values()
13 .filter(|x| !x.flags().contains(FieldFlags::SpecialName))
14 {
15 println!("\t{},", field.name());
16 }
17 } else {
18 for field in ty.fields().values() {
19 println!("\t{};", field);
20 }
21 }
22
23 println!("\n");
24
25 for method in ty.methods().values() {
26 println!("\t{};", method);
27 }
28
29 println!("}}");
30 }
31}
Sourcepub fn all_fields(&self) -> EntryCollection<'_, Field> ⓘ
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());
}
Sourcepub fn all_methods(&self) -> EntryCollection<'_, Method> ⓘ
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());
}
Sourcepub fn all_params(&self) -> EntryCollection<'_, Param> ⓘ
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());
}
Sourcepub fn all_type_specs(&self) -> EntryCollection<'_, TypeSpec> ⓘ
pub fn all_type_specs(&self) -> EntryCollection<'_, TypeSpec> ⓘ
Returns all the type specs defined in the module.
Sourcepub fn module_ref(&self) -> EntryCollection<'_, ModuleRef> ⓘ
pub fn module_ref(&self) -> EntryCollection<'_, ModuleRef> ⓘ
Returns all the modules refrenced in the module.
Sourcepub fn assembly_ref(&self) -> EntryCollection<'_, AssemblyRef> ⓘ
pub fn assembly_ref(&self) -> EntryCollection<'_, AssemblyRef> ⓘ
Returns all the assemblies refrenced in the module.