Attribute Instance

An attribute instance is an instance of the attribute class. You initialize an attribute instance with the named and positional arguments.

Compiling the Attribute

There are a number of steps that are performed when the compiler encounters an attribute in C# code. The steps are as follows:

1.
When the compiler encounters a statement that instantiates an attribute, it locates a constructor for the attribute class.
2.
If a public constructor is found, it is invoked.
3.
If the constructor found does not have public accessibility, a compilation error occurs.
4.
For each named argument mentioned for the attribute, a nonstatic read-write public field or property must be present in the attribute. If no such field or property ...

Get Special Edition Using C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.