Attributes that make ReSharper's and Rider's code inspections more accurate
open sourceMITfree
JetBrains.Annotations is a set of .NET attributes that tell JetBrains' .NET IDEs, ReSharper and Rider, what they can't infer from code alone, so their inspections give fewer false positives and catch more. NotNull and CanBeNull (and ItemNotNull and ItemCanBeNull for collection items and task results) declare nullability, Pure and MustUseReturnValue flag ignored return values, UsedImplicitly marks members used through reflection so they aren't reported as unused, StringFormatMethod checks format strings against their arguments, and ContractAnnotation states input and output contracts. Other attributes cover regular expressions, value ranges, disposable resources, and the special semantics of ASP.NET MVC, Razor and XAML APIs. It comes from NuGet as a compiled package or a source-code-only package, and the declarations can also be copied into a project from ReSharper's options.
Problems it solves
- ReSharper warns about possible null references that can't happen
- Rider reports members used only through reflection as unused
- declare which of my C# methods can return null so the IDE checks callers
Features
- nullability attributes (NotNull, CanBeNull)
- Pure and MustUseReturnValue
- UsedImplicitly for reflection
- StringFormatMethod format checks
- ContractAnnotation contracts
- ASP.NET MVC, Razor and XAML attributes
- compiled or source-only NuGet package