Create a Host

CCI Code Model

The CCI libraries are not associated with any particular application environment. From a CCI perspective, issues such as file locations or the targeted .NET version are matters of application policy. An application host object handles the details of implementing application policies and presents the results to CCI through a standard interface.

CCI Metadata includes a standard host object, Microsoft.Cci.PeReader.DefaultHost, which is sufficient for many CCI applications, including HelloCodeModel. DefaultHost* is implemented as a nested class in the Microsoft.Cci.PeReader class. HelloCodeModel creates an instance of DefaultHost, as follows:
MetadataReaderHost host = new PeReader.DefaultHost( )
NameTable nameTable = host.NameTable;

For details, see Hosts.

When you create a host by using the default constructor, as shown in the example, the host creates a Microsoft.Cci.NameTable object and assigns it to the NameTable property. NameTable is a utility object that is used by the host and other members of the CCI libraries to improve string-comparison performance. NameTable contains a table of key-value pairs, each of which consists of a string and a unique integral key. You can thus test string equality by comparing keys instead of the much slower process of going through the strings character-by-character.

For details, see The NameTable Object.

After the NameTable object is created, add appropriate strings by passing each one to NameTable.GetNameFor. This method creates a unique key for the string, stores the data, and returns the key-value pair as a Microsoft.Cci.IName interface. If the string is already in the table, GetNameFor simply returns the key-value pair. You usually pass names or other strings to CCI methods in the form of an IName interface, obtained by calling GetNameFor.

For details, see The IName Interface.

Next: Create and Configure an Assembly Object
Return to Beginning

Last edited Mar 9, 2010 at 7:19 PM by Guy_Smith, version 1


No comments yet.