The Merge into pattern inspection can now deal with many more code patterns. Fuse null checks with other checks into a single pattern check:
Rewrite checks from
conditional?.Access expressions to nested
if statement nesting by merging the checks together:
Finally, you can merge patterns inside a simple
deconstruction pattern by expanding them to full forms:
We’ve added more support for C# 9.0 records. The Extract interface and
Extract superclass refactorings now work with
record declarations, as do
File Layout and the features that have to do with XML documentation.
We’ve come up with a set of new inspections and actions.
Redundant explicit property declaration for properties in
can be of help while migrating your code to use records with positional parameters
and implicit property declarations. A corresponding quick-fix,
Remove explicit property, is included.
If you decide to turn a
record into a
class, the To class action will take
care of the positional parameters and primary constructor. There’s a To record
action that works the opposite way as well.
Whenever you need to rewrite positional parameters and a primary constructor
to ordinary properties, constructor, and an explicit
method, consider using the To explicit constructor context action.
There’s also something to keep things neat: the
Redundant 'record' type declaration body inspection and the corresponding
quick-fix will replace the empty
record type declaration body with a semicolon.
Find usages now searches for the usages of a record’s primary constructor
and for the usages of an implicit
We’re happy to introduce a new inspection, Inline temporary variable. Sometimes you find yourself using the same value over and over under different names in your program. Can such code be made more transparent? Sure, and ReSharper is here to help.
It can even help you find bugs if the temporary variable was supposed to be initialized to some other value or mutated later in code.
Logical not patterns can help you make your type checks much easier to read.
ReSharper offers dropping the
!() syntax in favour of a not pattern.
ReSharper now suggests using the range operator instead of
if doing so simplifies the code.
The Namespace does not correspond to file location inspection is now suppressed in files with top-level code.
There’s another new inspection that checks whether an auto-property can be replaced with a computed property, along with a quick-fix to make the replacement.
For C# 10.0 support, we’ve taken some first steps and taught ReSharper to work with the Constant interpolation strings feature.
Stay tuned for a dedicated blog post with all of the details on Code Analysis in 2021.1!
Route templates are widely used in MVC applications to configure how HTTP requests are matched to the application’s executable endpoints. In 2021.1 we’re introducing support for route templates: ReSharper now provides structural navigation, inspections, and quick-fixes. Let’s see some examples.
The most basic inspections check route template syntax errors: accidentally placing a catch-all parameter route in the middle of the template, declaring the catch-all parameter as optional, adding a default value for the optional parameter, and so on.
Route parameters are the source of interesting cases. What if you declare a parameter with the same name in the controller and in the action? ReSharper will warn you about it.
On the other hand, parameters can be missing. In this case, ReSharper will suggest you add them, either from the controller’s attribute or from the action. If there’s a type constraint, it will be used to infer the type of the parameter.
Speaking of constraints, they’re a good place for code analysis. ReSharper checks whether the applied constraint itself is correct, and whether a parameter actually satisfies the constraint.
ReSharper also tries to analyze whether the parameter type can be more strict – based on the constraint – and may suggest changing the type. If you’ve used the different type for the parameter on purpose, then just dismiss the suggestion.
ReSharper is aware of custom constraints as well. If in some cases they aren’t
recognized, annotate your constraint class with the
attribute provided by
As for other features from our standard pack, there’s code completion, structural navigation, and rearranging the code.
Renaming the route parameters doesn’t need to be manual anymore: the Rename refactoring is here for you.
Named tuples have been with us since C# 7, but renaming the components remained a manual operation. We’ve put an end to it – you can call the refactoring now.
You now have a new navigation action – Navigate to Windows Explorer. You’ll find it in the Navigate | Navigate to menu or by pressing Ctrl+Shift+A and typing its name. This can be useful if you are doing something with the file itself, like copying it or copying the path inside the repository, or if you prefer to view the file’s VCS history using Git extensions for Windows Explorer.
While we’re still dismantling ReSharper for ‘out of process’ mode and putting it back together, we never stop fixing specific performance issues where it’s possible. Here are some highlights.
We’ve added a couple of new settings:
For custom naming rules, we have updated the order in which they are applied: more specific ones now go first.
Finally, we’ve added a new action for Format Selection. You can now tell ReSharper to only adjust the indents for the selected code instead of performing the whole reformatting process.
EditorConfig is becoming a popular tool in the .NET community, and we’re continually improving how it works with ReSharper. Here’s what we’ve changed:
csharp_indent_case_contents_when_blockoption in EditorConfig.
[InlineAutoData]attribute, and warns you if there is no
[Test]attribute on the test class or method.
ReSharper C++ 2021.1 brings support for several new C++20 and C++17 language
features: class types in non-type template parameters, C++20 class template
argument deduction rules, and
noexcept as a part of the function
type. There are also new code completion items for coroutines available both
in basic code completion and as postfix completion templates:
We've introduced a collection of syntax style settings that you can use to enforce the chosen code style for the syntax constructions. With the supporting inspections, quick-fixes, and the Apply Syntax Style and Cleanup selection context actions, you can apply the new style to the codebase with ease and keep the new code consistent.
Free 30-day trial