Name

AssemblyBuilder

Synopsis

This class represents a dynamic assembly. A dynamic assembly is the root container for all the builder objects in the System.Reflection.Emit namespace. You can create an AssemblyBuilder object by using the DefineDynamicAssembly( ) method of the System.AppDomain class. When you create a dynamic assembly, specify a name and the access mode, using the AssemblyBuilderAccess enumeration. If you plan to save the assembly to disk using the the Save( ) method, be sure to specify AssemblyBuilderAccess.Save or AssemblyBuilderAccess.RunAndSave.

A dynamic assembly can contain one or more modules, which are defined by ModuleBuilder objects. Use the DefineDynamicModule( ) method to define, create, and return a ModuleBuilder object, as in ModuleBuilder myModB = myAssemblyB.DefineDynamicModule("ModuleName");. By default, this is a transient module that cannot be saved, regardless of the AssemblyBuilderAccess specified. To create a module that can be saved to disk, use a version of the overloaded DefineDynamicModule( ) that requires a fileName argument. You can also use other methods to add an attribute to the assembly, add or create managed and unmanaged resources, and retrieve a System.IO.FileStream object for any of the files in the assembly.

When you are finished creating an assembly and all its members, you can use the Save( ) method. This method takes a simple filename as a parameter, which can’t include directory or drive information. To use a different directory ...

Get C# in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.