CHAPTER 18 UNDERSTANDING CIL AND THE ROLE OF DYNAMIC ASSEMBLIES
System.Boolean bool
bool
BOOLEAN
System.String string
string
N/A
System.Object object
object
N/A
System.Void void
void
VOID
Note The System.IntPtr and System.UIntPtr types map to native int and native unsigned int (this is good
to know, as many of COM interoperability and P/Invoke scenarios use these extensively).
Defining Type Members in CIL
As you are already aware, .NET types may support various members. Enumerations have some set of
name/value pairs. Structures and classes may have constructors, fields, methods, properties, static
members, and so on. Over the course of this book’s first 17 chapters, you have already seen partial CIL
definitions for the items previously mentioned, but nevertheless, here is a quick recap of how various
members map to CIL primitives.
Defining Field Data in CIL
Enumerations, structures, and classes can all support field data. In each case, the .field directive will be
used. For example, let’s breathe some life into the skeleton MyEnum enumeration and define the following
three name/value pairs (note the values are specified within parentheses):
.class public sealed enum MyEnum
{
.field public static literal valuetype
MyNamespace.MyEnum A = int32(0)
.field public static literal valuetype
MyNamespace.MyEnum B = int32(1)
.field public static literal valuetype
MyNamespace.MyEnum C = int32(2)
}
Fields that reside within the scope of a .NET System.Enum-derived type are qualified using the static
and literal attributes. As you would guess, these attributes set up the field data to be a fixed value
accessible from the type itself (e.g., MyEnum.A).
Note The values assigned to an enum value may also be in hexadecimal with a 0x prefix.
670