Chapter 27. Attributes

In This Chapter

  • Using Attributes

  • Using Attribute Parameters

  • Using Attribute Targets

  • Creating Your Own Attributes

  • Getting Attributes from a Class

Attributes are program elements that decorate code to provide declarative functionality and metadata for a program. Metadata is the information about a program, its internal elements, and any other aspects of the code that may be interesting to developers. Other languages and systems use Interface Definition Language (IDL), interfaces, type libraries, and basic reflection to obtain metadata on programs.

C# uses reflection, which is a way to discover information about a program at runtime, to obtain metadata, but uses attributes to express additional metadata. Attributes provide a ...

Get C# Unleashed 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.