Skip to content

Latest commit

 

History

History
15 lines (8 loc) · 1.93 KB

ii.21.2-attributes-used-by-the-cli.md

File metadata and controls

15 lines (8 loc) · 1.93 KB

II.21.2 Attributes used by the CLI

There are two kinds of custom attributes, called genuine custom attributes, and pseudo custom attributes. Custom attributes and pseudo custom attributes are treated differently, at the time they are defined, as follows:

  • A custom attribute is stored directly into the metadata; the 'blob' which holds its defining data is stored as-is. That 'blob' can be retrieved later.

  • A pseudo custom attribute is recognized because its name is one of a short list. Rather than store its 'blob' directly in metadata, that 'blob' is parsed, and the information it contains is used to set bits and/or fields within metadata tables. The 'blob' is then discarded; it cannot be retrieved later.

Pseudo custom attributes therefore serve to capture user directives, using the same familiar syntax the compiler provides for genuine custom attributes, but these user directives are then stored into the more space-efficient form of metadata tables. Tables are also faster to check at runtime than are genuine custom attributes.

Many custom attributes are invented by higher layers of software. They are stored and returned by the CLI, without its knowing or caring what they 'mean'. But all pseudo custom attributes, plus a collection of genuine custom attributes, are of special interest to compilers and to the CLI. An example of such custom attributes is System.Reflection.DefaultMemberAttribute. This is stored in metadata as a genuine custom attribute 'blob', but reflection uses this custom attribute when called to invoke the default member (property) for a type.

The following subclauses list all of the pseudo custom attributes and distinguished custom attributes, where distinguished means that the CLI and/or compilers pay direct attention to them, and their behavior is affected in some way.

In order to prevent name collisions into the future, all custom attributes in the System namespace are reserved for standardization.