New Code Inspections in ReSharper 7September 12th, 2012 by Dmitri Nesteruk
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.
Here is a sampling of some new inspections that are making appearance in ReSharper 7.
iskeyword implicitly performs a
nullcheck, ReSharper will now warn if you’re also performing the
Plenty of API calls support overloads which take
stringformatting specifications, but if you use
string.Format()in those overloads explicitly, ReSharper will complain about the redundant call:
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:
ReSharper is acutely aware of the
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
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!
We hope you find these inspections useful in your day-to-day programming practice. Good luck!