Inspect and fix C# code
In Smart Mode, each file that you open in the editor is analyzed on the fly with hundreds of code inspections:
Status indicator in the top-right corner displays the number of code issues detected in the file. You can hover over it to see how many issues of different severity levels are found.
All detected issues are underlined with different colors according to the severity level of the corresponding inspection. For example, red means error (the code will likely not compile), yellow means warning (a compiler warning or suboptimal code), grey means suggestion (an improvement suggestion that can be safely ignored).
Markers on the scrollbar show relative positions of issues within the file, which help navigate code issues in large files.
To see why a part of code is underlined as a code issue, hover over the highlighting:
To go to the next/previous issue in the file, press ⌘ E/⌘ ⇧ E.
For most of the detected issues, there are one or more quick-fixes. To see available fixes, press ⌥ ⏎, then select the desired fix and press ⏎.
Switch context for multiple target frameworks
Results of code inspection can vary depending on the target .NET Framework because different versions of the framework have different features and capabilities, which can affect the behavior of the code. In most cases, each file belongs to a single project that targets a single .NET Framework, so JetBrains Fleet can unambiguously set a specific framework version context for code inspection in that file.
However, there are two cases when a file can be compiled with different framework versions:
Multiple framework versions are defined in the project file where the file belongs.
A file belongs to several projects with different framework versions.
In both cases, the framework version of the current context appears in the bottom-right corner of the editor, and you can click it to switch the context to another version. In the case of multiple frameworks in the project, the context will be switched for the whole project; otherwise, only the file context will be changed.
In the example above there are two unresolved calls in the file — Exception()
and ArgumentException()
— but only the second call is highlighted as error because the first one if filtered out for .NETCoreApp 3.1 with the #IF
directive and .NETCoreApp 2.0 is selected for analysis.