Intrinsic Attributes
Attributes come in two flavors:
intrinsic
and custom
.
Intrinsic
attributes are supplied as part of the
Common Language Runtime (CLR), and they are integrated into .NET.
Custom
attributes are attributes you create for
your own purposes.
Most programmers will use only intrinsic attributes, though custom attributes can be a powerful tool when combined with reflection, described later in this chapter.
Attribute Targets
If
you
search through the CLR, you’ll find a great many attributes.
Some attributes are applied to an assembly, others to a class or
interface, and some, such as [WebMethod]
, to class
members. These are called the attribute targets
.
Possible attribute targets are detailed in Table 18-1.
Table 18-1. Possible attribute targets
Member Name |
Usage |
---|---|
|
Applied to any of the following elements: assembly, class, class member, delegate, enum, event, field, interface, method, module, parameter, property, return value, or struct |
|
Applied to the assembly itself |
|
Applied to instances of the class |
|
Applied to classes, structs, enums, constructors, methods, properties, fields, events, delegates, and interfaces |
|
Applied to a given constructor |
|
Applied to the delegated method |
|
Applied to an enumeration |
|
Applied to an event |
|
Applied to a field |
|
Applied to an interface |
|
Applied to a method |
|
Applied to a single module |
Get Programming 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.