Chapter 3. The Metadata System


Chapter 2 described the different types that the CLR supports and demonstrated how developers can define new types as well as use types defined in other languages. The essential facility that enables such type sharing between compilers is the metadata system, which is the focus of this chapter.

Metadata is not a new concept. Language-specific metadata facilities have existed for a number of years ; a header file in C/C++, for example, is a metadata facility. A C++ header file may contain the declaration of a new type, such as a structure or class. By including such a header file in their own source files, other developers may program against the new type. A header file is a severely limited metadata facility, for several reasons. First, a C/C++ header file is, of course, language-specific. Second, it does not contain the entire definition of the type; at some point, a linker must resolve the abstract declaration of the type with its implementation, which is usually contained in an object file or a dynamically linked library (DLL). Multilanguage component architectures require much more sophisticated metadata services than these ”for example, types must be made available across language boundaries. Previously, this extra sophistication required extra complexity. Today, the CLR provides these facilities with little impact on developers.

The CLR also extends the use of metadata to provide not only information about types but also information about assemblies, the unit of deployment in the .NET Framework. As a consequence, both assemblies and types are self-describing . The execution engine uses this information to ensure correct runtime execution of code ”for example, making sure that version requirements are honored.

This chapter begins with a brief description of how other component architectures implement their metadata facilities. Next, it considers how developers may interact with the metadata system. Most developers will not need to know how metadata is created; rather, compilers will automatically generate and persist this information for them. For this reason, the discussion initially concentrates on how developers use and manipulate the metadata system, although an overview of metadata creation appears later in the chapter. This chapter also describes how developers can create their own metadata annotations using custom attributes. It explains how metadata describes assemblies, why and what metadata is generated, and how that metadata is used. In addition, it looks at the meta-programming facilities offered by the .NET Framework. Finally, the chapter provides an overview of how .NET metadata can be translated for use with COM, and vice versa.



Programming in the .NET Environment
Programming in the .NET Environment
ISBN: 0201770180
EAN: 2147483647
Year: 2002
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net