1
2
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! High-level builders for common .NET patterns.
//!
//! This module provides high-level builder APIs that compose the existing low-level
//! infrastructure to create common .NET constructs with fluent, ergonomic interfaces.
//!
//! # Architecture
//!
//! The builders follow a layered composition approach:
//! - **Layer 1**: High-level builders (MethodBuilder, ClassBuilder, etc.)
//! - **Layer 2**: Method body builders (MethodBodyBuilder)
//! - **Layer 3**: Low-level components (InstructionAssembler, MethodDefBuilder, etc.)
//!
//! This design maximizes reuse of existing tested components while providing
//! convenient high-level APIs for common scenarios.
//!
//! # Examples
//!
//! ## Simple Class Creation
//!
//! ```rust,no_run
//! use dotscope::prelude::*;
//!
//! # fn example() -> dotscope::Result<()> {
//! # let view = CilAssemblyView::from_path("test.dll")?;
//! # let mut assembly = CilAssembly::new(view);
//! // Create a complete class with properties and methods
//! let class_token = ClassBuilder::new("Person")
//! .public()
//! .namespace("MyApp.Models")
//! .auto_property("Name", TypeSignature::String)
//! .auto_property("Age", TypeSignature::I4)
//! .method(|_m| MethodBuilder::new("GetInfo")
//! .public()
//! .returns(TypeSignature::String)
//! .implementation(|body| {
//! body.implementation(|asm| {
//! asm.ldstr(Token::new(0x70000001))? // "Person info"
//! .ret()?;
//! Ok(())
//! })
//! }))
//! .default_constructor()
//! .build(&mut assembly)?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Simple Method Creation
//!
//! ```rust,no_run
//! use dotscope::prelude::*;
//!
//! # fn example() -> dotscope::Result<()> {
//! # let view = CilAssemblyView::from_path("test.dll")?;
//! # let mut assembly = CilAssembly::new(view);
//! // Create a simple addition method
//! let method_token = MethodBuilder::new("Add")
//! .public()
//! .static_method()
//! .parameter("a", TypeSignature::I4)
//! .parameter("b", TypeSignature::I4)
//! .returns(TypeSignature::I4)
//! .implementation(|body| {
//! body.implementation(|asm| {
//! asm.ldarg_0()?
//! .ldarg_1()?
//! .add()?
//! .ret()?;
//! Ok(())
//! })
//! })
//! .build(&mut assembly)?;
//! # Ok(())
//! # }
//! ```
// Re-export the main builders for convenience
pub use ClassBuilder;
pub use EnumBuilder;
pub use EventBuilder;
pub use InterfaceBuilder;
pub use MethodBuilder;
pub use MethodBodyBuilder;
pub use PropertyBuilder;