In addition to CIL instructions, a .NET assembly contains full, complete, and accurate metadata,
which describes each and every type (class, structure, enumeration, and so forth) defined in the
binary, as well as the members of each type (properties, methods, events, and so on). Thankfully, it
is always the job of the compiler (not the programmer) to emit the latest and greatest type metadata.
Because .NET metadata is so wickedly meticulous, assemblies are completely self-describing
entities.
To illustrate the format of .NET type metadata, let’s take a look at the metadata that has been
generated for the Add() method of the C# Calc class you examined previously (the metadata generated
for the VB .NET version of the Add() method is similar):
CHAPTER 1 n THE PHILOSOPHY OF .NET 15
TypeDef #2 (02000003)
-------------------------------------------------------
TypDefName: CalculatorExample.Calc (02000003)
Flags : [NotPublic] [AutoLayout] [Class]
[AnsiClass] [BeforeFieldInit] (00100001)
Extends : 01000001 [TypeRef] System.Object
Method #1 (06000003)
-------------------------------------------------------
MethodName: Add (06000003)
Flags : [Public] [HideBySig] [ReuseSlot] (00000086)
RVA : 0x00002090
ImplFlags : [IL] [Managed] (00000000)
CallCnvntn: [DEFAULT]
hasThis
ReturnType: I4
2 Arguments
Argument #1: I4
Argument #2: I4
2 Parameters
(1) ParamToken : (08000001) Name : x flags: [none] (00000000)
(2) ParamToken : (08000002) Name : y flags: [none] (00000000)
Metadata is used by numerous aspects of the .NET runtime environment, as well as by various
development tools. For example, the IntelliSense feature provided by tools such as Visual Studio
2008 is made possible by reading an assembly’s metadata at design time. Metadata is also used by
various object browsing utilities, debugging tools, and the C# compiler itself. To be sure, metadata is
the backbone of numerous .NET technologies including Windows Communication Foundation
(WCF), XML web services/the .NET remoting layer, reflection, late binding, and object serialization.
Chapter 16 will formalize the role of .NET metadata.
No comments:
Post a Comment