Rider Help

Annotations in Source Code

The easiest way to benefit from Rider's code annotations is to add the annotation attributes to symbols of your source code and make 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 Rider code annotations support in your project

To make use of Rider code annotation attributes in your project, you should reference them in one of the following ways:

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:

Quick-fix for adding reference to the JetBrains.Annotations module

Using Context Actions to add annotation attributes

As soon as Rider is aware of annotation classes location, you can use context actions to add the most popular annotation attributes:

  • [NotNull]
  • [CanBeNull]
  • [UsedImplicitly]

To add these annotations, press Alt+Enter on the symbol you want to annotate, and Rider will suggest an attribute depending on the context:

/help/img/rider/2017.1/annotation_ca.png
Last modified: 11 October 2017

See Also