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
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!("}}");
}
}
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?
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!("}}");
}
}
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.