5

Leveraging Attributes

We briefly touched on the concept of C# attributes in Chapter 2, Metaprogramming Concepts. They are an obvious choice for adding explicit metadata to your source code. This is what they are intended for. Attributes should not carry heavy logic with them and should be viewed as just metadata.

In this chapter, we will look into how you can leverage them in your code base, providing mechanisms for adorning types and members with valuable, rich information that can be used for different scenarios.

We will cover the following topics:

  • What is an attribute and how can it be applied?
  • Finding types with specific attributes
  • Generic attributes

From this chapter, you should understand the power of attributes as a building block ...

Get Metaprogramming in 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.