.NET Tools News Releases ReSharper Platform

ReSharper 2023.1 EAP 8 Is Here With Improved Support for C# and C++

You can download the latest ReSharper 2023.1 Early Access Program build from our website. But before you do it, let’s take a look at the updates in this build.

C# support

Insert a return type specification for lambdas

Lambda expressions in C# usually have implicitly-typed parameters and an inferred return type. Sometimes, it can be useful to add explicit types in a signature of a lambda expression to make code clearer or to help C# type inference in some complex scenarios involving overload resolution. A context action to insert parameter types, Insert parameter signature, has been around for a while.

Starting from C# 11, adding a return type specification for lambda expressions is also possible. To accomplish this, we introduced a new context action, Insert return type specification, in version 2023.1. You can apply it to all lambda expressions in scopes like method, class, file, project, or an entire solution.

Syntax style for null checking patterns

We provided the new “Syntax style” setting to help you enforce one consistent style of not null checks inside patterns. It consists of 2 options: empty recursive pattern syntax { } and negated pattern not null, where the latter is set by default. You can adjust the behavior on the ReSharper | Options | Code Editing | C# | Syntax Style page. 

There is a disadvantage to using the not null pattern – you cannot introduce variable names for the checked value as you can with the recursive pattern { LastName: { } lastName }. Workarounds like { LastName: not null and var lastName } are not as concise as a recursive pattern. To help resolve this, we’ve added the Add pattern variable context action over the not null pattern. This Add pattern variable context action now looks for expressions accessing the same value (since we are introducing a variable name) and replacing all of them with the newly introduced name to consolidate all accesses to the same value.

ArgumentNullException.ThrowIfNull style of null checks

.NET 6.0 SDK introduced a new API for null checking – ArgumentNullException.ThrowIfNull. Our code analysis engine has recognized this checking approach since then, but there was no option to use this API as a default style of null checks produced in ReSharper. In the 2023.1 release, we added an ArgumentNullException.ThrowIfNull pattern to ReSharper | Options | Code Editing | C# | Null checking.

Pattern is redundant inspection

C# or/and/not patterns can be useful to produce compact value checks without repeating the input value reference (value == 1 || value == 2 vs. value is 1 or 2). However, this syntax is still not as recognizable as good older expressions like ||/&&/!. Pattern priorities are not that clear at first, so it is easy to miss parentheses and introduce hard-to-find bugs.

For example, the expression value is not 0 or -1 compiles without any warnings. When the user’s intention is to check the value for being not equal to both 0 or 1, this check will evaluate to true with the value being equal to -1. The correct pattern to use would be value is not (0 or -1).

To help with situations like this, we introduced a new code analysis in version 2023.1 to warn you about “dead” checks inside complex patterns. Usually, those redundant “dead” pattern checks indicate a problem with a complex pattern.

Convert to list pattern context action

We’re continuing to improve our support for C# 11 list patterns. With the new Convert to list pattern context action, you can turn collection length checks into a list pattern syntax. It works in any context where a collection length check can be done.

C++ support

ReSharper 2023.1 EAP 8 comes with the following updates for C++:

  • We’ve introduced support for the C++20 __VA_OPT__ macro.
  • The Rename refactoring now works on named modules and module partitions.
  • The Introduce using enum and Convert to scoped enum refactorings are now available as context actions via the Alt+Enter menu.
  • We’ve added 2 new inspections: Template parameter is never used and Function result of type HRESULT/NTSTATUS should be used.

You can learn more about these changes from this dedicated blog post. 

That’s it for now!

For the full list of improvements and fixes that made it into the latest EAP build, please check out our issue tracker. As always, we’d love to hear your opinions and suggestions in the comments below.  

Discover more