Annotations in Source Code
The easiest way to benefit from JetBrains Rider's code annotations is to add the annotation attributes to symbols of your source code and make JetBrains Rider analyze your solution with greater accuracy and insight.
By default, all annotation attribute classes are marked with
[Conditional("JETBRAINS_ANNOTATIONS")] so the compiler will ignore the attribute usages in your code, which means that no binary reference to the 'JetBrains.Annotations.dll' assembly will be produced. However, you can define 'JETBRAINS_ANNOTATIONS' conditional compilation symbol in your projects to preserve the attributes in metadata.
Enabling JetBrains Rider code annotations support in your project
To make use of JetBrains Rider code annotation attributes in your project, you should reference them in one of the following ways:
- The recommended way is to install the NuGet package with the
If the JetBrains.Annotations.dll is referenced or attribute declarations are inserted in any of the projects within your solution, you can type the desired annotation attribute and press Alt+Enter to invoke the quick-fix that will reference this module in the current project and add the missing namespace import directive:
Using Context Actions to add annotation attributes
As soon as JetBrains Rider is aware of annotation classes location, you can use context actions to add the most popular annotation attributes:
To add these annotations, press Alt+Enter on the symbol you want to annotate, and JetBrains Rider will suggest an attribute depending on the context: