CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Tuesday, June 24, 2008

.NET Assemblies Tutorial Part 4 of 5

.NET Assemblies Tutorial Part 1 of 5 - An Overview of .NET Assemblies
.NET Assemblies Tutorial Part 2 of 5 - Single-File and Multifile Assemblies
.NET Assemblies Tutorial Part 3 of 5 - The Role of the Common Intermediate Language
.NET Assemblies Tutorial Part 4 of 5 - The Role of .NET Type Metadata
.NET Assemblies Tutorial Part 5 of 5 - The Role of the Assembly Manifest

The Role of .NET Type Metadata

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, functions, events, and so on). Thankfully, it is always the job of the compiler (not the programmer) to define the latest and greatest type metadata. Because .NET metadata is so wickedly meticulous, assemblies are completely self-describing entities—so much so, in fact, that .NET binaries have no need to be registered into the system registry.

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 VB Calc class you examined previously (the metadata generated for the C# version of the Add() method is similar):

TypeDef #2 (02000003)
-------------------------------------------------------
TypDefName: CalculatorExample.Calc (02000003)
Flags : [Public] [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)


Despite what you may be thinking, metadata is a very useful entity (rather than an academic detail) consumed by numerous aspects of the .NET runtime environment, as well as by various development tools. For example, the IntelliSense feature provided by 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 Visual Basic 2008 compiler itself. To be sure, metadata is the backbone of numerous .NET technologies including Windows Communication Foundation, reflection services, late binding facilities, XML web services/the .NET remoting layer, and the object serialization process.

.NET Assemblies Tutorial Part 1 of 5 - An Overview of .NET Assemblies


.NET Assemblies Tutorial Part 2 of 5 - Single-File and Multifile Assemblies


.NET Assemblies Tutorial Part 3 of 5 - The Role of the Common Intermediate Language


.NET Assemblies Tutorial Part 4 of 5 - The Role of .NET Type Metadata


.NET Assemblies Tutorial Part 5 of 5 - The Role of the Assembly Manifest


Post a Comment