What’s new in ReSharper 2022.2

ReSharper 2022.2 includes support for C# 11 features such as required members, checked user-defined operators, raw strings, and list patterns. The solution-wide analysis has greatly optimized memory consumption. Additionally, this release also brings the Virtual Formatter, which allows you to view code in your preferred format without actually reformatting the source code on the disk, and a Disk Cleanup tool to remove temporary files generated by ReSharper while it works on your code.

Download

Free 30-day trial available

C# 11

This release brings support for several more features from the C# 11 preview.

Required Members

In C# 11, class, struct, and record types gained the ability to declare a list of required members. This is the list of all properties and fields that are considered required and must be initialized during the initialization of a type’s instance. Types inherit these lists from their base types automatically, providing a seamless experience that removes boilerplate, repetitive code.

Apart from being aware of the required keyword for members inside a class, struct, or record type, ReSharper provides additional support for the required keyword:

  • There is a required keyword in the code completion.
  • Most of the compiler errors and warnings are available.
  • The required modifier has been added to the Modifiers order on the ReSharper | Options | Code Editing | C# | Syntax Style page.

We’ve added a new Add initializer for required members quick-fix for cases where you’ve created a type’s object but haven’t initialized the members yet. It automatically generates all of the missing “required” members for your object – you just need to fill in the members’ values with meaningful data.

Checked user-defined operators

Checked user-defined operators help developers create user-defined operators that operate on types where arithmetic overflow is a valid concept. ReSharper shows all of the compiler errors and warnings. To fully support checked user-defined operators, ReSharper has a couple more inspections and a context action.

We’ve updated the Unchecked/checked context is redundant inspection to take into account checked operators when they are used in this context.

If you have a set of user-defined operators and some of them already have a checked version, ReSharper will help you propagate checked operators to the whole set. A new inspection called The operator does not have a matching checked operator while other operators do will notify you which operators don’t have a checked operator yet and suggest a quick-fix to generate the checked versions automatically.

If you haven’t used checked operators in your codebase yet, but want to start adding them, a new context action called Create matching checked operator will come in quite handy. It is available on every user-defined operator and generates a checked version of an operator right from the Alt+Enter menu in one click.

Raw strings

C# 11 improves the ability to embed other languages or text formats into C# code by introducing the concept of "raw" strings.

ReSharper has basic “raw” string support including compiler errors and correct parsing and color highlighting for """ syntax, pairs of double quotes, and placeholders inside interpolated strings ({{...}} syntax).

List patterns

C# 11 continues to expand the set of patterns available in the language. This time around, C# allows matching through list-like structures, such as arrays, strings, and List<T>-like collections.

ReSharper 2022.2 fully supports list patterns with error checking, code completion, and code analysis. We are still working to add code inspections to suggest using the list patterns in existing code and additional refactoring actions.

More C# 11 features

More C# 11 features

  • ReSharper 2022.2 fully supports the new unsigned right shift operator (>>>), including support for user-defined operator >>> overloading.
  • ReSharper 2022.2 supports simplifying the use of Span<char> values as a replacement for string instances, since in C# 11 it's possible to directly pattern-match string constants against the values of type Span<char> and ReadOnlySpan<char>.

Solution-wide analysis optimizations

In this release, we've greatly optimized the memory usage of ReSharper with the Solution-Wide Analysis mode turned ON, both in terms of memory traffic (number of memory allocations) and in terms of memory consumption.

The Solution-Wide Analysis engine uses memory to store the list of issues in the solution and to store the type/member usage information to perform solution-wide usage reporting (code inspections like "public member is never used"). The usage data is "hot", meaning it needs to be constantly updated while you are editing the code, and can’t be off-loaded to the disk. This can consume a significant amount of memory if your solution contains lots of types and type members. We reviewed the data stored in memory and found patterns that allowed us to deduplicate/normalize the data. We also utilized specialized collection types to further reduce the working set. These optimizations resulted in a 5-10x memory consumption improvement and faster Solution-Wide Analysis loading.

Code Analysis

Top-level statements

.NET 6 introduced new project templates with the use of C# 9 top-level statements. Top-level statements simplify declaring a Program class or public static void Main(string[] args) method. But sometimes the explicit startup class Program is necessary or more desirable to use. ReSharper 2022.2 adds the new context action To explicit 'Program' class to execute a transformation to the old style.

At the same time, if you have an existing Program startup class and wish to migrate to top-level statements, we've got you covered with a new Convert to top-level code context action.

Updates to the INotifyPropertyChanged support

In this release we reworked our INotifyPropertyChanged support. It no longer relies on external annotations to detect common INotifyPropertyChanged APIs, which allowed us to support more MVVM frameworks and INotifyPropertyChanged base classes automatically. We now emit a SetField method that enables the most concise syntax for INotifyPropertyChanged notifications.

It's also now possible to add property change notifications for all of the properties in the type or file.

Refactorings in the Alt+Enter menu

To increase the discoverability of refactorings, we reviewed the most commonly used refactorings and introduced related context actions in the Alt+Enter menu that depend on the current context.

We've added the Extract method context action when you call the Alt+Enter menu on a selected piece of code.

Change Signature, Transform Parameters, Convert to extension method, and Convert Property To Method refactorings are all now available as context actions over member signatures.

More suggestions for using a nameof operator

ReSharper 2022.2 now recognizes the registrations of DependencyProperty in WPF projects and suggests using a nameof operator to capture the corresponding CLR property name. Built-in live templates were also updated to emit nameof instead of string literals.

Often ReSharper can’t recognize the special meaning of a particular string literal in your code that is used to specify the name of some code entity like a member or type name. For these cases, we've introduced a new Capture element name context action for string literals with identifiers that can reference a code entity in the context containing the string literal.

Structural Search and Replace

Quick-fixes which come from Structural Search And Replace (SSR) patterns can now be applied in the scope of a file, folder, project, or entire solution. It affects user custom patterns created on the ReSharper | Options | Code Inspection | Custom Patterns page, ReSharper built-in code inspections, and the corresponding fixes based on the SSR.

Other

ReSharper 2022.2 now detects some assignment patterns in your code and suggests more idiomatic C# code with pattern matching.

ReSharper 2022.2 is now able to replace some is patterns under ?: expressions with the more concise as under the ?? expression, effectively eliminating a temporary variable.

Virtual Formatting

We’ve introduced the Virtual Formatter — a way for you to view code with your desired formatting without actually reformatting the source code on the disk. For example, you can now virtually align parameters in columns or increase indents. Our goal with this feature is to improve readability and maintainability of code and make it more accessible for visually impaired and neurodivergent developers. To enable the Virtual Formatter with predefined settings, go to ReSharper | Options | Environment | Inlay Hints | General. To further tailor the formatting to your exact specifications, check the Use dedicated Virtual Formatter style settings checkbox and click C#.

Disk Cleanup

You can now remove temporary files generated by ReSharper while it is working on your code. We’ve added a new page in Options where you can:

  • Observe a set of default paths and files ReSharper can remove.
  • Add a custom path template for files you want to be removed.
  • Specify after how many days ReSharper should consider files outdated for each path template.
  • Check how much space is occupied by files matched by each path template.
  • Set up automatic cleanup for outdated files which will run periodically (the default value is 1 day).
  • Run the cleanup manually for different scopes.

JavaScript and TypeScript support

As many of you might have noticed, JavaScript and TypeScript support in ReSharper is outdated and slow. In the current implementation, it's difficult to follow TS language changes and support new versions quickly, so we are looking for a better way to support these languages. After a long internal discussion, we've decided to put our current JS and TS support on hold. As a result, we've disabled TS/JS support by default in this release. If you still want to use it, you can re-enable it here: ReSharper | Options | Environment | Products & Features | the "JavaScript and TypeScript" checkbox.

Unreal Engine

ReSharper C++ introduces Blueprint-specific inlay hints and allows you to see the bigger picture behind your code:

  • Be aware of derived Blueprint classes and check out the list of all inheritors.
  • Spot that a UFunction has implementations in Blueprints and search for all such cases.
  • Quickly check the state of a UProperty, including whether it has been overridden and what value is set in the Blueprint file.

We’ve also added inspections to let you know if there are inconsistencies between the Blueprint-specific function specifiers used in the code and the Blueprints themselves.

Improved support for native system calls dotUltimate

dotTrace now provides more details for native system calls in the Timeline Call Tree, including Windows kernel calls (ntoskrnl.exe), device driver calls (*.sys), and more.

Respect settings from StyleCop.Analyzers

ReSharper can now detect if the StyleCop.Analyzers package is referenced by a project and read its settings from the stylecop.json and .ruleset files. File headers and indentation settings are lifted from stylecop.json, while StyleCop rules are applied in accordance with the active .ruleset file setup.

ReadyToRun and NGen assemblies

  • The way ReadyToRun (R2R) and NGen assemblies are presented in the Assembly Explorer has been improved. A small processor symbol icon and ngen or R2R labels are now displayed next to each assembly's name.
  • The Metadata tree has the ReadyToRun header.
Download

Free 30-day trial available