Daily Archives

One Article

Visual Studio Tips

Using JetBrains Code Annotations

Posted by matteskolin on

List of Attributes https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html

How to Install
run the below in your .NET project directory

dotnet add package JetBrains.Annotations

The JetBrains.Annotations library provides ways to improve the quality of the Resharper Code Analysis. By applying the annotation attributes, the code suggestions, intellisense, and warnings can be improved as resharper is provided with information that it cannot determine without them by examining the original code. There many attributes available; see link above.

Example: [UsedImplicity]

This attribute indicates that the marked symbol is used implicity, in a way which is not detectable by code analysis. Some examples are via reflection, an external librar, or as a record type argument like in the below example..

You can use ImplicitUseKindFlags and ImplicitUseTargetFlags to configure how this attribute is applied.

Before adding attribute, resharper reports a warning that Response is not used.. even though we can see this type being passed as the type argument of the IRequest above.. Removing the Response record type, even causes a compile error, but resharper is unable to detect this.. This may be because the actual instantiation is happening inside of the MediateR library, which is not being analyzed..

After adding the attribute..