Free mag vol1 | Page 617

CHAPTER 15  TYPE REFLECTION, LATE BINDING, AND ATTRIBUTE-BASED PROGRAMMING Examining a TypeRef Recall that an assembly’s metadata will describe not only the set of internal types (Car, EngineState, etc.), but also any external types the internal types reference. For example, given that CarLibrary.dll has defined two enumerations, you find a TypeRef block for the System.Enum type, as follows: TypeRef #1 (01000001) ------------------------------------------------------Token: 0x01000001 ResolutionScope: 0x23000001 TypeRefName: System.Enum Documenting the Defining Assembly The ildasm.exe metadata window also allows you to view the .NET metadata that describes the assembly itself using the Assembly token. As you can see from the following (partial) listing, information documented within the Assembly table is (surprise, surprise!) the same information that can be viewable via the MANIFEST icon. The following is a partial dump of the manifest of CarLibrary.dll (version 2.0.0.0): Assembly ------------------------------------------------------Token: 0x20000001 Name : CarLibrary Public Key : 00 24 00 00 04 80 00 00 // Etc... Hash Algorithm : 0x00008004 Major Version: 0x00000002 Minor Version: 0x00000000 Build Number: 0x00000000 Revision Number: 0x00000000 Locale: Flags : [PublicKey] ... Documenting Referenced Assemblies In addition to the Assembly token and the set of TypeDef and TypeRef blocks, .NET metadata also makes use of AssemblyRef #n tokens to document each external assembly. Given that the CarLibrary.dll makes use of the System.Windows.Forms.MessageBox class, you find an AssemblyRef for the System.Windows.Forms assembly, as shown in the following code: AssemblyRef #2 (23000002) ------------------------------------------------------Token: 0x23000002 Public Key or Token: b7 7a 5c 56 19 34 e0 89 Name: System.Windows.Forms Version: 4.0.0.0 Major Version: 0x00000004 Minor Version: 0x00000000 Build Number: 0x00000000 Revision Number: 0x00000000 Locale: 559