CustomAttribute Metadata Table

CustomAttribute Metadata Table

The CustomAttribute table contains data that can be used to instantiate custom attributes at run time. A record in this CustomAttribute table has three entries:

  • Parent (coded token of type HasCustomAttribute)  This entry references the metadata item to which the attribute is assigned.

  • Type (coded token of type CustomAttributeType)  This entry defines the type of the custom attribute itself.

  • Value (offset in the #Blob stream)  This entry is the binary representation of the custom attribute’s parameters.

Given their nature, as informational add-ons to other metadata items, custom attributes can be attached to any metadata item that has a specific token type assigned to it. The one exception is that custom attributes cannot be attached to another custom attribute. Chapter 4, “Metadata Tables Organization,” described the 21 token types. The token type mdtString (0x70000000) is assigned to user strings, which are not part of the metadata tables, and mdtCustomAttribute (0x0C000000) belongs to the custom attributes themselves. This leaves us with 19 tables providing potential owners of custom attributes: Module, TypeRef, TypeDef, Field, Method, Param, InterfaceImpl, MemberRef, DeclSecurity, StandAloneSig, Event, Property, ModuleRef, TypeSpec, Assembly, AssemblyRef, File, ExportedType, and ManifestResource. No metadata table references the CustomAttribute table. Note that a custom attribute can be assigned to a specific type (TypeRef, TypeDef), but not to an instance of the type.

The Type entry of a custom attribute is a coded token of type CustomAttributeType and hence theoretically can be one of the following: TypeRef, TypeDef, Method, MemberRef, or String. (See the section “Coded Tokens” in Chapter 4.) In fact, in the first release of the common language runtime, the choice is limited to Method or MemberRef because of the requirement that the type of a custom attribute must be an instance constructor and nothing else. The class whose instance constructor represents the custom attribute type should be derived from the abstract class [mscorlib]System.Attribute.

The Value entry of a custom attribute is a blob whose contents depend on the nature of the custom attribute. If we were allowed to use a user-defined string as the custom attribute type, Value would contain the Unicode text. But because the custom attribute type is limited to instance constructors, the Value blob contains the encoded arguments of the constructor. If the constructor has no parameters, because the mere presence of the custom attribute is considered sufficiently informational, the Value entry can hold 0.



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