How-To's

New Code Inspections in ReSharper 7

As with every release, ReSharper comes with a number of inspections and fixes for diverse real-life development scenarios. This post illustrates both new inspections and quick-fixes as well as improvements to already existing analyses.

Inspection Smorgasbord

Here is a sampling of some new inspections that are making appearance in ReSharper 7.

  • Since an is keyword implicitly performs a null check, ReSharper will now warn if you’re also performing the null check explicitly:

  • Plenty of API calls support overloads which take string formatting specifications, but if you use string.Format() in those overloads explicitly, ReSharper will complain about the redundant call:

  • When using OrderBy()-related LINQ methods, ReSharper will now complain if there is more than one such method in a call chain, and will offer to fix the situation by using a Then-prefixed method in the second call:

Also, ReSharper now provides usage inspections in response to Contract Annotations, which are explained in a separate post.

Quick-Fixes for Possible Multiple Enumerations

In ReSharper 6, we introduced an inspection to detect possible multiple enumerations of IEnumerable. In ReSharper 7, we have augmented this feature with quick-fixes to turn the enumeration into either a list or an array:

Both of the options replace the original declaration type with either an array or a list, calling the appropriate LINQ conversion method if necessary. Variable creation action also offers to use either var or an enumerable type:

Async/Await-Related Inspections

ReSharper is acutely aware of the async and await keywords and their proper use in .NET applications. Its support begins with basic recognition of missing or redundant keywords, together with appropriate fixes. For example, performing an await in a non-async method offers the following fixes:

ReSharper also takes care of various problematic use cases, such as having ref or out parameters in an async method:

Surround Templates as Context Actions

ReSharper has for a long time offered a separate command called Surround With Template (Ctrl+E,U) to surround blocks of code with different types of braces and preprocessing instructions. However, to make the feature even more convenient, ReSharper now offers these options as context actions when a block of code is selected. The top-level menu offers curly and round braces, with additional options offered in the submenu:

… and a lot more!

In addition to the examples above, ReSharper comes with a wealth of inspections and fixes for Windows Runtime applications as well as JavaScript. We have also previously demonstrated some inspections specific to various ReSharper features, such as INotifyPropertyChanged support and unit testing.

We hope you find these inspections useful in your day-to-day programming practice. Good luck!

image description