This project is read-only.

Member Definition Objects

CCI Metadata

Type members are represented by member definition objects. Each type of member has a separate definition object. The Microsoft.Cci.MutableCodeModel.MethodDefinition object represents a method’s metadata, Microsoft.Cci.MutableCodeMode.PropertyDefinition represents properties, and so on.
The following example from the HelloIL sample creates and configures a MethodDefinition object to represent the Test class’s Main method.
MethodDefinition mainMethod = new MethodDefinition() {
  ContainingType = testClass,
  InternFactory = host.InternFactory,
  IsCil = true,
  IsStatic = true,
  Name = nameTable.GetNameFor("Main"),
  Type = host.PlatformType.SystemVoid,
  Visibility = TypeMemberVisibility.Public,
assembly.EntryPoint = mainMethod;

The following sections describe the configuration details.

The ContainingType Property

This property represents a NamespaceTypeDefinition object for the type that contains the method.

The InternFactory Property

The InternFactory property represents the same InternFactory object object that is used for type metadata.

The IsXYZ Properties

One or more MethodDefinition.IsXYZ properties are set to true to characterize the member. The example sets two properties:
  • IsCil indicates that Main is implemented in the Common Language Interface (CLI) Common Intermediate Language.
  • IsStatic indicates that Main is a static method.
Other possibilities include IsConstructor, IsGeneric, and so on.

The Name Property

The Name property contains the member name’s IName interface. The example specifies “Main” as the method name.

The Type Property

Set the Type property to the method’s return type. For system types, you can set Type to a value from the Microsoft.Cci.PlatformType class. Main is a void type so the example sets Type to PlatformType.SystemVoid.

The Visibility Property

The Visibility property contains a value from the Microsoft.Cci.TypeMemberVisibility enumeration that specifies the method’s visibility. The assembly’s entry point must be public, so the example sets Visibility to TypeMemberVisibility.Public.

Add Member Metadata to the Class and the Assembly

If you are working with a mutable representation, you add configured member definition objects to the type metadata. Main is the assembly’s entry point, so the example also assigns the Main method’s MethodDefinition object to the Assembly object’s EntryPoint property. You do not need to set Assembly properties for ordinary methods.

The NamespaceTypeDefinition.Methods property is a list of the type’s methods. The example adds Main to the Test class's metadata by passing the MethodDefinition object to Methods.Add. For other kinds of members, add them to the appropriate list, such as NamespaceTypeDefinition.Properties.

Last edited Mar 17, 2010 at 4:49 PM by Guy_Smith, version 5


No comments yet.