Represents an assembly that is being defined at runtime and can be saved to disk.
The AssemblyBuilder
class is used to dynamically generate and save assemblies. It provides methods to define types, methods, fields, and other members within the assembly. This is particularly useful for scenarios like Just-In-Time (JIT) compilation, code generation, and dynamic proxies.
An AssemblyBuilder
is created by calling the DefineDynamicAssembly
method on an AssemblyBuilderAccess
object. You can then use the ModuleBuilder
obtained from the AssemblyBuilder
to define types. The types can then be defined and populated with members such as methods, fields, and properties.
After defining the assembly content, you can save the assembly to a file using the Save
method.
protected AssemblyBuilder(AssemblyName name, AssemblyBuilderAccess access)
Initializes a new instance of the AssemblyBuilder
class with the specified assembly name and access mode.
protected AssemblyBuilder(AssemblyName name, AssemblyBuilderAccess access, Evidence evidence)
Initializes a new instance of the AssemblyBuilder
class with the specified assembly name, access mode, and evidence.
public ModuleBuilder DefineDynamicModule(string name)
Defines a dynamic module in this assembly and returns a ModuleBuilder
object.
public ModuleBuilder DefineDynamicModule(string name, string versionID)
Defines a dynamic module in this assembly with the specified name and version identifier.
public void Save(string assemblyFileName)
Saves the dynamic assembly to disk.
public void Save(string assemblyFileName, PortableExecutableKind portableExecutableKind, ImageFileMachine imageFileMachine)
Saves the dynamic assembly to disk with specified PE kind and image file machine type.
public bool IsDynamic
Gets a value that indicates whether the assembly was generated dynamically.
Namespace: System.Reflection.Emit
Assembly: System.Private.CoreLib
(in .NET Core, .NET 5+)
Assembly: System.Reflection.Emit
(in .NET Framework)