O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required