Aspects are custom attributes applied to target declarations. Some aspects target methods, while others target properties or classes.
In this article, you'll learn how to add aspects using custom attributes.
Adding aspects as custom attributes
Assume you have a method that occasionally fails.

Currently, CodeLens displays No aspect, indicating that no aspect has been applied to this method.
Note
The CodeLens feature is only available in Visual Studio when Visual Studio Tools for Metalama are installed. See Configuring your IDE for IDE-specific information.
To apply the Retry aspect, add it as a standard custom attribute by typing [Retry]:

CodeLens now displays 1 aspect. Hover your cursor over that text to reveal the following tooltip:

To view the details, click on the text 1 aspect:

The details displayed in this example are trivial. However, this feature is useful when you have several aspects on the same method or when aspects are implicitly applied without a custom attribute.
Adding multiple attributes
Add as many aspects as needed to a target method. In this example, to log each retry attempt, add the Log aspect.

CodeLens now shows that two aspects have been applied to the method FlakyMethod. Click on the text 2 aspects to view the details provided by CodeLens:

Adding aspects via the refactoring menu
Instead of manually adding attributes, add them through the refactoring menu. Access this menu by clicking the lightbulb or screwdriver icon or by pressing Ctrl + ..

The refactoring menu displays three aspects that can be applied to this method. Hover over a menu item to preview your code with the aspect custom attribute.
The refactoring menu recognizes which aspects have already been applied and adjusts its recommendations accordingly. The following screenshot shows that after applying the Retry aspect, the refactoring menu only displays the remaining available aspects.

Note
The refactoring menu only displays aspects that are eligible for your code. The aspect author determines eligibility. For example, a caching aspect wouldn't make sense on a method returning void, so the aspect author might restrict it to non-void methods only.