JetBrains Rider 2022.2 Help

Code Annotations

This page of JetBrains Rider settings allows you to obtain the code annotation attribute classes as well as to make related configurations.

JetBrains Annotations - official NuGet package

Click this link to go to the JetBrains Annotations home page where you can obtain the annotations using NuGet.

Automatically propagate annotations

If this check box is selected, some JetBrains Rider features will automatically insert annotation attributes. For example, the 'Check parameter for null' context action will add the [NotNull] attribute in addition to generating code that checks for nullness.

Default annotation namespace

Allows you to choose the namespace where JetBrains Rider looks for code annotation types. This option may be helpful if you have the same annotation types in several namespaces. For more information, see Annotations in source code.

List of namespaces with code annotation attributes

JetBrains Rider automatically detects namespaces in the solution and referenced assemblies with valid annotation attribute types and displays the list of these namespaces, if any.

The default implementation of the annotation attributes are declared in the JetBrains.Annotations namespace, but this namespace is not required for the annotations to work. You can put the declarations anywhere in your solution — JetBrains Rider will detect them automatically. However, if the declarations are in a different namespace you should explicitly specify the namespace with annotation attributes as described below.

There also may be cases when your solution contains several implementations of the annotation attributes, for example, you have classes with the same names as JetBrains Rider annotations classes (CanBeNullAttribute, NotNullAttribute, and so on) or you are using a third-party assembly that contains JetBrains Rider annotation classes. In such cases, you can choose namespaces where JetBrains Rider should look for the proper set of the annotations-attributes classes.

Annotations source code

In this section, you can copy the source code of the JetBrains.Annotations namespace to clipboard so that you can embed the declarations in the desired place in your solution.

Before copying the annotations, you can customize the classes in two ways:

  • Click internal to make the annotations classes internal, that is only accessible within the module where you insert them.

  • Click conditional to add the [Conditional("JETBRAINS_ANNOTATIONS")] attribute to the classes. This will make the compiler ignore the annotation attributes in your code, which means that no binary reference to the 'JetBrains.Annotations.dll' assembly is produced. However, you can define 'JETBRAINS_ANNOTATIONS' conditional compilation symbol in your projects to preserve the attributes in the metadata.

Last modified: 28 December 2021