hao 0.0.17

Read, edit, create and write .net assemblies
Documentation
//! Loads an assembly and prints its types and constant field values, showcasing
//! the typed APIs: `use hao::prelude::*;`, `TypeDef::kind` (the C# keyword
//! instead of a hand-rolled classification), and `Constant::decode` ->
//! `ConstantValue`.
//!
//! Usage: `cargo run --example load_module -- <assembly.dll>`

use hao::prelude::*;

fn main() {
    let path = std::env::args()
        .nth(1)
        .expect("usage: load_module <assembly>");
    let module = Module::from_path(&path).unwrap();
    println!("loaded {}", module.name());

    for ty in module.all_types() {
        let ty = ty.get();
        println!("{} {}.{}", ty.kind().keyword(), ty.namespace, ty.name);

        // Decode compile-time constants (enum members and `const` fields) into a
        // typed value, rather than hand-reading the raw blob.
        for field in &ty.fields {
            let field = field.get();
            if let Some(value) = field.constant.as_ref().and_then(Constant::decode) {
                println!("    {} = {value}", field.name);
            }
        }
    }
}