Order of Manifest Declarations in ILAsm

Order of Manifest Declarations in ILAsm

The general rule in ILAsm (and not only in ILAsm) is “declare, then reference.” In other words, it’s always safer, and in some cases outright required, to declare a metadata item before referencing it. There are times when you can reference a yet-undeclared item—for example, calling a method that is defined later in the source code. But you cannot do this in the manifest declarations.

If we reexamine the diagram shown in Figure 5-1, which illustrates the mutual references between the manifest metadata tables, we can discern the following list of dependencies:

  • Exported types reference files and enclosing exported types.

  • Manifest resources reference files and external assemblies.

  • Every manifest item can have associated custom attributes, and custom attributes reference external assemblies and (rarely) external modules. (See Chapter 13 for details.)

To comply with the “declare, then reference” rule, the following sequence of declarations is recommended for ILAsm programs, with the manifest declarations preceding all other declarations in the source code:

  1. AssemblyRef declarations (.assembly extern), because of the custom attributes. The reference to the assembly Mscorlib should lead the pack because most custom attributes reference this assembly.

  2. ModuleRef declarations (.module extern), again because of the custom attributes.

  3. Assembly declaration (.assembly). Because the ILAsm compiler takes different paths in compiling Mscorlib.dll and compiling other assemblies, it is better to let it know which path to take as soon as possible. However, this is less important if you are not compiling Mscorlib.dll; by default the compiler assumes that it is compiling a “conventional” module.

  4. File declarations (.file) because ExportedType and ManifestResource declarations might reference them.

  5. ExportedType declarations (.class extern), with enclosing ExportedType declarations preceding the nested ExportedType declarations.

  6. ManifestResource declarations (.mresource).

note

Remember that only the manifests of prime modules carry Assembly and ExportedType declarations.



Inside Microsoft. NET IL Assembler
Inside Microsoft .NET IL Assembler
ISBN: 0735615470
EAN: 2147483647
Year: 2005
Pages: 147
Authors: SERGE LIDIN

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