What’s new in ReSharper 2021.3

ReSharper 2021.3 supports the recently released Visual Studio 2022. Code Analysis improves C#10 support, including file-scoped namespaces and global using directives, nullable reference types, and general C# support. This release also adds Find Usages for user-defined implicit conversion operators, new gutter marks, and a significantly enhanced Copy Code Reference feature.

Download

Free 30-day trial available

Support for Visual Studio 2022

ReSharper now supports the release build of the new Visual Studio 2022. You will have access to the same rich feature set you are already used to having in other Visual Studio versions. But since Visual Studio 2022 is a x64 process, there is no longer a limit to the maximum amount of memory that can be allocated to it. As a result, all ReSharper features work faster.

To use ReSharper with this new version of Visual Studio, make sure the VS2022 icon in the dotUltimate 2021.3 installer is selected.

C# 10

C# 10 was recently released, and ReSharper continues to add more C# 10 features. Today, we are happy to add support for file-scoped namespaces, global usings, the CallerArgumentExpression attribute, the “interpolated string handlers” concept, and C# 10 lambdas.

Let’s start with file-scoped namespaces. In addition to supporting the new syntax itself, we’ve added a new Syntax style option that allows you to select your desired style (ReSharper | Options | Code Editing | C# | Syntax Style | Code body | Namespaces). When you choose a style, ReSharper will show you inspections for code that has to be changed to follow the style, and it will suggest the appropriate quick-fixes for you. You can propagate the fixes through the project or even through the whole solution in one click.

There are now two context actions that allow you to return your code to the previous syntax style: Convert to file-scoped namespace and Convert to block-scoped namespace.

Learn more: File-Scoped Namespaces

Now let’s take a quick look at global usings. ReSharper code analysis is aware of usings marked with the global keyword, and it uses them to correctly resolve symbols in all the code files in the project. ReSharper will also notify you if a global using has been put in the wrong place in a file.

ReSharper will highlight global usings that have no usages in the project as unused, and it will offer a quick-fix to remove the statement.

ReSharper brings rich support for the CallerArgumentExpression attribute, including code completion and code inspections to help you use it properly.

Learn more: Caller Argument Expressions

C# 10 introduced the new concept of "interpolated string handlers". For end users, this means that string interpolation expressions generally work faster in .NET 6, and the new handlers also make it possible to use Span<char> values in interpolation holes. For library authors, this feature allows them to control whether string interpolation expressions are converted to strings. ReSharper 2021.3 recognizes the "interpolated string handlers" pattern in library code and can now safely suggest using string interpolation expressions in more places.

ReSharper helps you get the best performance out of record structs by suggesting that you mark them as readonly. To avoid cluttering type declarations with modifiers unnecessarily, this inspection is only shown when the record type has non-mutating instance members and there are no mutations via setters in the solution (requires enabled solution-wide analysis).

C# 10 lets you simplify the pattern matching syntax a bit by allowing dotted access instead of object pattern nesting.

ReSharper offers the corresponding inspection with a quick-fix, as well as a context action to undo the quick-fix.

And last but not least:

  • We've improved support for C# 10 lambdas: neither red code nor false positive errors are expected in .NET 6 Minimal API projects. As a bonus, ReSharper also helps you use the correct syntax and add parentheses where they’re expected by the compiler.
  • ReSharper now supports “Program” as a valid generated class name for code with top-level statements.
  • Initial support for static abstract members in interfaces is now available. Code analysis considers this construction as valid, which means you should no longer have to deal with red code. The Generate missing members feature is aware of static abstract members and handles them correctly. This release also includes inheritance gutter marks and the ability to navigate to base/derived symbols.

Nullable reference types

It is not unusual for people to copy pieces of code from other resources, like stackoverflow.com. Nowadays, with nullable reference types available in C#, some code samples already include the NRT syntax. But what if you don’t have NRT enabled in your solution? ReSharper has two new quick-fixes to help you get rid of this syntax after pasting such code into your project: Replace with JetBrains.Annotations attributes and Remove nullable annotations without ‘#nullable’ context.

From time to time, there may be nullability mismatches between type arguments and their nullability constraints. There are now quick-fixes for such cases, including ones that:

  • Remove nullable annotations from type arguments.
  • Remove notnull constraints from type arguments.
  • Allow nullable values in type parameters.
  • Disallow nullable values in type parameters used as type arguments.

A bulk quick-fix is available for correcting annotations on parameters with nullable default values in a file, project, or whole solution.

There is also a new bulk quick-fix that makes a parameter nullable if it's checked for null within a method.

Code analysis

We’ve added a couple of new quick-fixes and a context action for static local/anonymous functions with closures:

  • The Allow closures quick-fix removes static modifiers from a local or an anonymous function if it contains closures.
  • The Pass closure as a parameter quick-fix lifts closures in static local functions to parameters.
  • The Pass closure as a parameter context action lifts closures in non-static local functions to parameters.

There is a new inspection, Simplify string interpolation, with a corresponding quick-fix that replaces .PadLeft() and .PadRight() method calls with alignment expressions inside interpolated string placeholders.

In addition to adding the new C#10 record struct, we have also improved our support for regular structs. Many developers still use classes with object initializers for their DTOs. Now you can quickly transform all these usages to constructors with parameters. This can be done either from the record declaration itself or from any object initializer. Note that also DTOs that define a constructor with property assignments can be converted.

For some time already, ReSharper has warned you about inconsistent locks on fields. In this version, we’re adding a complementary inspection that also takes the order of several locked resources into account, informing you about possible deadlock cycles.

ReSharper now checks the plausibility of integral arithmetic expressions for additional integer types, including byte, sbyte, short, ushort, uint, long, ulong, and enum. This helps you avoid unreachable code branches.

To make long and complex conditions easier to read, we've added highlighting for condition elements. It highlights groups of logical operators, e.g. && and || chains in C#.

Code analysis performance

We've reduced the time it takes for quick-fixes and context actions to be implemented when they are invoked for a folder, project, or solution.

If Solution-Wide Error Analysis (SWEA) is enabled with Monitor warnings, ReSharper now uses SWEA results to simply skip the files without corresponding issues, greatly reducing the amount of time spent finding issues to fix.

We also have good news for those who don’t run SWEA on their solutions! ReSharper now utilizes all available CPU cores to run code analysis in parallel. This reduces the overall time it takes to execute scope quick-fixes and context actions.

 

We’ve significantly improved the performance of the daemon for files that contain huge methods, such as the following:

  • Methods with large or nested conditional expressions, tuple expressions, or switch expressions.
  • Methods with lots of type checks when nullable reference types are disabled.
  • Methods with a lot of indexer accesses when nullable reference types are enabled.
  • Methods with a huge number of closures when nullable reference types are enabled.

Navigation and Find Usages

New gutter marks

We’ve added a few more gutter marks to help you quickly navigate through the inheritance structure of a class, interface, or struct. The new ↑O and ↑I icons show that a code entity inherits or implements another class or interface, respectively. If this code entity’s inheritance is complex, selecting an icon will display a menu with all of its ancestors above it, up to the top of the inheritance hierarchy. If a class implements or inherits an interface and a class simultaneously, ReSharper shows an ↑IO icon in the gutter.

Additionally, in this release we’ve enabled the gutter mark for class members by default. ReSharper will add the ↓O icon in the left gutter next to a class member if the class member is overridden in derived classes. Clicking on the icon will:

  • Navigate you to a member in a derived class that overrides this member.
  • Show you a menu with a list of class members from other classes that override this member.

Find Usages for user-defined implicit conversion operators

Now you can call Find Usages for user-defined implicit conversion operators! The implementation of this feature is based on the mechanism used for type conversion hints.

It allows you to find out whether user-defined implicit conversion operators are used at all, and then navigate to blocks of code with conversions.

Please be aware that this algorithm is not fast, and it can take quite some time to calculate and display its findings.

Navigate to interface implementations in debug mode

When you invoke Go to Type of Symbol on a variable or parameter of an interface type in debug mode, ReSharper will take you to the exact implementation of it that is used in the current frame, rather than the interface declaration.

Language injections

You can now mark any of a function’s parameters, fields, or properties with the [LanguageInjection] annotation attribute. ReSharper will consider a string value of a marked code entity as a code fragment in a specified language. The following languages can be injected: CSS, HTML, JavaScript, JSON, or XML. As soon as you add the attribute, you will get proper syntax highlighting, code completion, and other features inside the string. You need to add the latest version of JetBrains.Annotations to your project to use the LanguageInjection attribute.

Copy Code Reference

This release brings a lot of changes to the Copy FQN feature. First of all, the feature has a new name, Copy Code Reference. We think this name better reflects what the feature does.

We've added new functionality if you use Git as a version control system. There are GitHub-related items in the Copy Code Reference pop-up out of the box for projects cloned from GitHub. They generate a proper link to a GitHub repository to share it with anyone right away.

For non-GitHub repositories, you can now add custom URI templates in your ReSharper settings. All of these templates will appear in the Copy Code Reference pop-up. A URI template can consist of various predefined placeholders like Current Branch Name, File Name, Current Line Number, etc.

Finally, the pop-up itself has been given a significant facelift. It’s design, icons, and formatting are all new.

Formatting

  • We've added an option to indent lambda or property pattern braces inside statement conditions, such as inside if(), while(), and so on.
  • We've added an option to align statement conditions inside the parentheses in if(), foreach(), etc., and it’s turned ON by default.
  • We've added options to wrap, chop, align, and outdent binary patterns, for example, x is Foo or Bar or Baz.

Create new Unreal Engine classes

With ReSharper C++ 2021.3, you no longer need to switch to Unreal Editor to create a new class – all predefined templates for Unreal Engine classes are now available in the list of ReSharper file templates.

To create a new class, go to Solution Explorer and right-click on the preferred project folder to open the Add menu (or use Ctrl+Alt+Insert). After you choose an Unreal Engine template from the list and give your new class a name, ReSharper C++ will generate the header and source files with the template code in the proper folders depending on the private or public context.

What’s new in ReSharper C++ 2021.3

Even better C++20 support

You can use C++20 designated initializers to quickly generate boilerplate code for aggregate initialization. Just select the corresponding item from the completion list to insert designators for the data members, and then provide the initial values.

In addition, ReSharper C++ 2021.3 brings inspections to help you adopt new library functions for erasing elements from any standard container, checking whether an element exists in an associative container, and creating smart pointers with default initialization.

What’s new in ReSharper C++ 2021.3

Support for AnalyzerConfig files

Starting with the .NET 5 SDK, you can use global AnalyzerConfig files to configure Visual Studio’s analyzer options. ReSharper 2021.3 can read code style information from these global AnalyzerConfig files and use it to adjust ReSharper’s rules accordingly.

Sampled memory allocation data dotUltimate

dotMemory can now get sampled data about memory allocation based on ETW events. Compared to the traditional (statistical) way of collecting allocation data, sampling is less accurate but provides a number of advantages:

  • The sampled allocation data is collected without performance penalties.
  • You don’t need to enable this data collection explicitly; it is always active.
  • Sampled allocation data can also be collected when you attach the profiler to an application that is already running.

Note that this feature is available only on Windows.

What’s new in dotMemory 2021.3

Download

Free 30-day trial available