Much of the C# language enables the programmer to specify declarative information about the entities defined in the program. For example, the accessibility of a method in a class is specified by decorating it with the method-modifiers public
, protected
, internal
, and private
.
C# enables programmers to invent new kinds of declarative information, to specify declarative information for various program entities, and to retrieve attribute information in a run-time environment. For instance, a framework might define a HelpAttribute
attribute that can be placed on program elements such as classes and methods to provide a mapping from program elements to documentation for them.
New kinds of declarative information are defined through the declaration of attribute classes (§17.1), which may have positional and named parameters (§17.1.2). Declarative information is specified a C# program using attributes (§17.2), and can be retrieved at run-time as attribute instances (§17.3).