Along with the Common Type System, metadata is at the heart of the CLI. CLI-compliant compilers generate metadata and store it with the code in the executable file according to the file format specified in Partition II, sections 21 24 (Chapter 5 of this book). Metadata describes the code by describing the types that the code defines and the types that the code references externally. There is enough information stored in the metadata to (among other things):
Metadata provides information to tools like debuggers and verifiers, and it permits communication between tools. Among the information the metadata contains is the following:
Figure 1-3 shows some of the possible users of metadata. Figure 1-3. Users of MetadataOne of the services of the CLI that uses metadata is called reflection. In the CLI, a reflection object represents a type, describes it, and is an in-memory representation of the type but is not an instance of the type. Reflection allows you to discover all of the information contained in metadata about a type, including the name of the type, its fields, its methods, whether it is public or private, any attributes attached to it, and more. Metadata simplifies the job of developing designers, debuggers, profilers, type browsers, and other tools by making the information they need easily available without making them walk the code to find it. Metadata is the key that enables cross-language programming. When a compiler reads a module compiled in a different language, it reads the metadata, thus allowing seamless interoperation, much as a traditional compiler might read a "header file" describing the other module; but by reading the metadata directly from the module, there's no possibility of reading the wrong header file and there is no need to generate a separate header file to describe your own code. Custom attributes were designed as part of the CLI to allow extensibility without requiring languages to continue to add new keywords. Custom attributes include markers for CLS compliance, security, debugging, and many language- and tool-specific attributes. Some custom attributes are defined by the CLI, but they can also be defined by a compiler or by the tools that use the attribute. Languages that identify as distinct types what the VES sees simply as 32-bit integers for example, C++, which distinguishes int from long even when both are 32-bit would create a custom attribute that would identify the different types to the compiler. Custom attributes are essential to tools. In a programming environment with designers, you might create a new button object. A custom attribute would tell the designer that this object is a button, and at runtime the designer would list it as one of the available buttons. If the VES that you're using includes a proxy generator, you could make an object available externally to a Web service by putting in a custom attribute telling the proxy generator to create a proxy for the object, and another attribute telling the Web service that the proxy should be included. Metadata stores custom attributes, making them readily available to any tool. Section 9 of Partition I (Chapter 2 of this book) is a discussion of the architecture of metadata. Sections 1 20 of Partition II (Chapter 3 of this book) define an assembly language based on the CIL, using it to define the semantics of metadata. |