Roslyn-based analysis of C# code to suggest the use of features in the latest version of the language.
To install this analyzer, in Visual Studio:
- Open menu
Tools->NuGet Package Manager->Manage NuGet Packages for Solution. TheNuGet - Solutionwindow appears. - In the top right corner, make sure
Package Sourceis selected to be eithernuget.orgorAll. - Click the
Browsetab and in the search prompt typeCSharpLatest. - A list of packages appears, one one them called
dlebansais.CSharpLatest. - Click to select this package and in the right pane check projects you want to be analyzed.
- Click the
Installbutton.
To uninstall this analyzer, in Visual Studio:
- Open menu
Tools->NuGet Package Manager->Manage NuGet Packages for Solution. TheNuGet - Solutionwindow appears. - Click to select the
dlebansais.CSharpLatestpackage and in the right pane uncheck projects you no longer want to be analyzed. - Click the
Uninstallbutton.
| Code | Diagnostic |
|---|---|
| CSL1000 | Variables that are not modified should be made constants. |
| CSL1001 | Use is null instead of == null |
| CSL1002 | Use is not null instead of != null |
| CSL1003 | Consider using primary contructors to simplify your code. |
| CSL1004 | Consider using records to simplify your code. |
| CSL1005 | Simplify one line getter. |
| CSL1006 | Simplify one line setter. |
| CSL1007 | Add missing braces. |
| CSL1008 | Remove unnecessary braces. |
| CSL1009 | FieldBackedPropertyAttribute is missing argument. |
| CSL1010 | init accessor not supported in FieldBackedPropertyAttribute. |
| CSL1011 | Implement params collection. |
| CSL1012 | Use System.Threading.Lock to lock. |
| CSL1013 | Change extension function to extension member |
| CSL1014 | Consider using <inheritdoc /> |
| CSL1015 | Do not declare async void methods |
| CSL1016 | Unsupported use of the AsyncEventHandler attribute. |
This diagnostic comes directly from the Roslyn Analyzer Tutorial.
Feature available since C# 7.0: is operator
Feature available since C# 9: logical patterns
Feature available since C# 12: primary constructors. Superseded by IDE0290.
Feature available since C# 9: records
Feature available since C# 6 (and extended to accessors in 7): expression body. Superseded by IDE0025 and IDE0027.
Feature available since C# 7: expression body. Superseded by IDE0027.
Improves on rule IDE0011.
The FieldBackedProperty attribute can be used in code conditionally compiled with and without C# 14 to emulate the functionality of the field keyword.
Feature available since C# 13: params collections.
Feature available since C# 13: New lock object.
Feature available since C# 14: Extension members.
Improve your code documentation with Visual Studio 2022 full support of this tag.
While async void methods are valid C# code, they should be avoided except for event handlers. This diagnostic helps you identify such methods in your code. For more information, see Asynchronous programming with async and await.
If the method is an event handler, consider using the AsyncEventHandler attribute. More information can also be found in the description of this diagnostic.
The AsyncEventHandler attribute can be used to handle async void methods, but under a restricted set of conditions. This diagnostic notifies you when these conditions are not met.