Write the Assembly to a File

CCI Metadata

The assembly is now complete. The simplest way to use the completed assembly is to write it to a .exe file and run the application. HelloIL writes the Hello assembly to a file named “hello.exe” as follows:
Stream peStream = File.Create("hello.exe");
PeWriter.WritePeToStream(assembly, host, peStream);      

The first line creates a standard .NET file stream. Microsoft.Cci.PeWriter.WritePeToStream is a static method that writes the assembly to the specified file stream. Notice that WritePeToStream also depends on the host for information about application policy.

Although you pass the Assemblyobject to WritePeToStream, the method’s first parameter is an IModule type (IAssembly inherits from IModule). What WritePeToStream receives is thus the immutable representation of the assembly, which it can traverse but not modify. HelloIL has now shifted to the Hello assembly’s immutable representation and does not make any further changes to the Assemblyobject.

For a discussion of immutable representations, see Mutable and Immutable Representations.

Return to Beginning

Last edited Dec 18, 2009 at 8:18 PM by Guy_Smith, version 1


No comments yet.