AssemblyBuilder

AssemblyBuilder

System.Reflection.Emit (mscorlib.dll) sealed class

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 or drive, you must specify the path when you create the dynamic assembly by using the appropriate constructor. When you save a dynamic assembly, all nontransient modules are saved using the filename specified when you created them. By default, the assembly is saved as a DLL file (as if you had used the /target:library command-line compiler switch). To change this, use the SetEntryPoint( ) method to specify the assembly's startup method and to specify PEFileKinds .

 public sealed class  AssemblyBuilder  : System.Reflection.Assembly {  // Public Instance Properties  public override string  CodeBase  {get; }  // overrides System.Reflection.Assembly  public override MethodInfo  EntryPoint  {get; }  // overrides System.Reflection.Assembly  public override string  ImageRuntimeVersion  {get; }  // overrides System.Reflection.Assembly  public override string  Location  {get; }  // overrides System.Reflection.Assembly   // Public Instance Methods  public void  AddResourceFile  (string   name   , string   fileName   );    public void  AddResourceFile  (string   name   , string   fileName   , System.Reflection.ResourceAttributes   attribute   );    public ModuleBuilder  DefineDynamicModule  (string   name   );    public ModuleBuilder  DefineDynamicModule  (string   name   , bool   emitSymbolInfo   );    public ModuleBuilder  DefineDynamicModule  (string   name   , string   fileName   );    public ModuleBuilder  DefineDynamicModule  (string   name   , string   fileName   , bool   emitSymbolInfo   );    public IResourceWriter  DefineResource  (string   name   , string   description   , string   fileName   );    public IResourceWriter  DefineResource  (string   name   , string   description   , string   fileName   ,        System.Reflection.ResourceAttributes   attribute   );    public void  DefineUnmanagedResource  (byte[ ]   resource   );    public void  DefineUnmanagedResource  (string   resourceFileName   );    public void  DefineVersionInfoResource  ( );    public void  DefineVersionInfoResource  (string   product   , string   productVersion   , string   company   ,        string   copyright   , string   trademark   );    public ModuleBuilder  GetDynamicModule  (string   name   );    public override Type[ ]  GetExportedTypes  ( );  // overrides System.Reflection.Assembly  public override FileStream  GetFile  (string   name   );  // overrides System.Reflection.Assembly  public override FileStream[ ]  GetFiles  (bool   getResourceModules   )  // overrides System.Reflection.Assembly  public override ManifestResourceInfo  GetManifestResourceInfo  (string   resourceName   )  // overrides System.Reflection.Assembly  public override string[ ]  GetManifestResourceNames  ( );  // overrides System.Reflection.Assembly  public override Stream  GetManifestResourceStream  (string   name   )  // overrides System.Reflection.Assembly  public override Stream  GetManifestResourceStream  (Type   type   , string   name   );  // overrides System.Reflection.Assembly  public void  Save  (string   assemblyFileName   );    public void  SetCustomAttribute  (System.Reflection.ConstructorInfo   con   , byte[ ]   binaryAttribute   );    public void  SetCustomAttribute  (CustomAttributeBuilder   customBuilder   );    public void  SetEntryPoint  (System.Reflection.MethodInfo   entryMethod   );    public void  SetEntryPoint  (System.Reflection.MethodInfo   entryMethod   , PEFileKinds   fileKind   ); } 

Hierarchy

System.Object System.Reflection.Assembly(System.Security.IEvidenceFactory , System.Reflection.ICustomAttributeProvider , System.Runtime.Serialization.ISerializable) AssemblyBuilder

Returned By

System.AppDomain.DefineDynamicAssembly( )



C# in a Nutshell
C # in a Nutshell, Second Edition
ISBN: 0596005261
EAN: 2147483647
Year: 2005
Pages: 963

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net