Code Analysis for C#
Solution-Wide Analysis
ReSharper 3.1 introduces a new feature called Solution-Wide Error Analysis (SWEA), which looks for errors in your solution on-the-fly, without compiling it first, then looking for errors, then fixing them, and repeating the whole thing over and over again.
All you have to do is explicitly switch SWEA on, and then, after it analyzes the code of your solution, view the list of errors in a dedicated window:
Even without opening that window, you can still easily navigate through errors in your solution with Go to Next Error in Solution (Alt+Shift+Page Down or Alt+F12) and Go to Previous Error in Solution (Alt+Shift+Page Up or Shift+Alt+F12) commands.
On-the-fly Error Checking
ReSharper instantly detects and highlights errors in code, without you having to compile it first. It automatically analyzes and highlights your code on the fly, while you work. If you roll the mouse pointer over an error, its description is displayed in a tooltip.
Warnings
Besides errors and warnings detectable by the compiler, ReSharper also prompts you about additional warnings that may represent real coding errors. For example, ReSharper informs you about redundant casts, incorrect format strings, declared but never used local variables, etc.
Code Suggestions
A deeper level of code analysis is available with Code Suggestions. Code suggestions provide insights into code structure, drawing your attention to things that aren't necessarily bad or wrong, but probably useful to know.
For instance, you may be interested to know that "parameter can be declared with base type," meaning that your method only uses members of the parameter's base type. This can be an indication of a different error, such as failure to take into account the specifics of the actual parameter type. Based on this knowledge, you may want to change the parameter's type - or not, if that is by design.
At any time, you can use ReSharper Options to change the severity of analysis results, assigning any particular inspection/notification to error, warning or code suggestion, to suit your individual or corporate coding requirements or style.
Quick-Fixes
ReSharper provides
Quick-fixes for most errors, helping you solve problems instantly. Quick-fixes are represented by
the red light bulb
that appears automatically to the
left of the code line containing the error, when you position the caret on the error. You can see the list of
available quick-fixes for a given error, either by clicking the light bulb or by pressing Alt +
Enter. Then simply select the appropriate quick-fix from the list, and it will implement the automatic error
correction.
Value Analysis
ReSharper provides a new type of on-the-fly error analysis called Value Analysis for analyzing null references and boolean values. It automatically detects when you access a variable that can possibly be null and immediately warns you about it. It can also suggest that a condition is always true or false at a specific point in code.
Additional sources for warnings can be customized and added via a dedicated Options page. You can define your own attributes, such as Nullable and NonNullable, which will be taken into account when checking for null references.
Status Indicator
You can instantly see whether the current file contains any errors or warnings, by looking at the sidebar that ReSharper adds to the right-hand side of the editor window. The status indicator at the top changes its color if the file contains errors or warnings. When you hover over it, the indicator shows the total number of errors and warnings in the current file.
Navigation Between Errors and Warnings
Each warning or error is represented by an individual stripe on the sidebar. Clicking on a stripe navigates you directly to the line of code that contains the error or causes the warning.
You can navigate between errors and warnings by pressing F12 (forward) and Shift + F12 (backward) (or Alt + PgDn/PgUp in our new Visual Studio shortcut scheme). You can also navigate between just errors (skipping any warnings) with Next Error and Previous Error commands. The error message corresponding to the current error or warning is displayed in the status bar.
Disabling Warnings at Specific Places
With the depth of code analysis come situations where ReSharper is overzealous with its insights. Sometime you know better that a particular piece of code is just fine and no warnings are necessary, so you can simply disable that warning at that specific place. This can be done with any warning. Of course, you can also disable and change the global display status of each error, warning or suggestion via the ReSharper Options dialog.
