Do you use temporary variables to swap variable values? There is now a more elegant way to do this! ReSharper 2021.2 will help you modernize your code with the new Swap via deconstruction quick-fix!
Reduce the number of allocations in your code, and increase throughput! Replace
empty array creation with
If you’re allocating a new
Type, ReSharper will suggest using
Type.EmptyTypes to make memory usage more efficient.
EventArgs are not required, ReSharper will let you know you can
new EventArgs() with
.editorconfigto mark files or folders as generated code and exclude them from processing.
Do you have lots of nullable warning suppressions in your code base after enabling nullable reference types?
ReSharper indicates suppressions (
!) that are no longer needed and that can
be safely removed.
A new context action lets you search for all nullable warning suppressions in scope. From the Find Results tool window, you can then re-evaluate whether the suppressions are needed or not.
We've introduced a new refactoring to change nullability! It’s available through
a quick-fix, through the Refactor This action, or through an in-place
refactoring when adding or removing the nullable annotation (
ReSharper will update nullability annotations, and suggest propagating the changes throughout your codebase.
Several new inspections with corresponding quick-fixes are available for when you’re using JetBrains.Annotations attributes and nullable reference types are enabled.
Update JetBrains.Annotations attributes to NRT syntax and compiler-supported
attributes! For example, ReSharper can update
[CanBeNull] string to
ReSharper will inform you about redundant JetBrains.Annotations attributes,
[NotNull] string or
[ItemCanBeNull] List<string?>. And
of course, it will offer a quick-fix to update your code.
When type annotation syntax is not allowed, a new inspection with a quick-fix adds compiler-supported annotations, e.g.:
[JetBrains.Annotations.NotNull] T paramto
[DisallowNull] T param(
where T: class?)
[System.Diagnostics.MaybeNull] T(in C# 8, where the
T?syntax is not allowed)
ReSharper adds new inspections and quick-fixes to help you with using
compiler-supported annotations such as
A new inspection detects redundant compiler annotations, such as when
[AllowNull] is applied to a nullable type, and a quick-fix removes them.
When nullable reference type syntax can be used, ReSharper will suggest doing so.
There are additional improvements that also deserve a mention:
Source Generators can be used to reduce tedious and repetitive development work, and to generate code at compile time. In ReSharper 2021.2, many of the features available for human-written code files are available for source-generated files as well. We’ve improved editor support, enhanced the debugger, and added support for Solution-Wide Error Analysis (SWEA) and refactorings.
For generated code, warnings and errors are displayed in the editor and on the marker bar.
Solution Wide Error Analysis (SWEA) now includes files generated by source generators. If there's an error in a generated file in your project, you'll be able to spot it immediately and navigate to it.
You can toggle this behavior using the new option to include source generated files, which is enabled by default and located in ReSharper | Options | Code Inspection | Settings | Enable solution-wide analysis.
Refactorings can now be triggered from source-generated files. Use the Rename refactoring to rename a generated property. ReSharper will also rename the related symbol in manually written code!
Similarly, Change Signature lets you verify whether code that will be generated after the change can still be compiled.
You can now use Find Usages, search for inheritors, navigate from generated code to manually written code with Ctrl+Click and Navigate To, and more.
Semantic highlighting is enabled so that class members like events, fields, and properties are highlighted correctly. All inlay hints are shown where appropriate.
ReSharper's own Data Tips are shown while debugging. This provides more powerful debugging assistance with the ability to search, property highlighting, and more.
ReSharper now supports code generated by source generators in VB.NET.
In the previous release, we implemented support for ASP.NET route templates. In the
v2021.2 release, we have continued in this direction and brought better support for
HttpClient URI strings:
HttpClient, code completion will suggest all URIs that can be resolved to actions in controllers annotated with
Useful features have been added for Navigation:
It can sometimes be useful to specify advanced naming rules for records, extension methods, and catch variables. Starting from this release, it’s possible to configure these rules.
If you prefer using a Pico brace (indenting) style, we’ve got you covered. The Pico style has been added as an option to the Brace Layout tab on the ReSharper | Options | Code Editing | C# | Formatting Style | Braces Layout page.
We’ve changed the default formatting preferences in a couple of cases to align with the Visual Studio defaults.
With the new Inline Function refactoring, you can quickly replace a function call with the body of the function. ReSharper C++ will perform the necessary transformations, handle all the name conflicts, and reformat the resulting code.
ReSharper C++ 2021.2 introduces inlay hints for implicit type conversions, which could have resulted in inadvertent data loss or performance issues. ReSharper C++ now indicates where implicit conversions happen in your code.
DPA now stores two values for each issue – the max value and the current value. This prevents false negatives, as it was previously possible for issues to fall below the threshold and disappear from the issue list, not because they had been fixed, but because their launch conditions had changed (the program ran for less time, the required functionality was not executed, and so on.)
The embedded decompiler can now decompile single-file apps. It supports single-file formats for the .NET Core 3.1, .NET 5, and the upcoming .NET 6 SDKs. Using Assembly Explorer, you can browse through bundled assemblies inside a single-file app, just like you are used to doing.
In this release, we have continued to improve the way you analyze memory allocation. Two new tabs have been added to the Memory Allocation view:
Razor developers working on large views can turn off the CPU-intensive assistance and automatic suggestions if their editor begins to lag. You can find the settings here: ReSharper | Options | Environment | Editor | Behavior | Razor | Allow CPU-intensive typing assist.
We introduced a breaking change in the InspectCode tool. Starting from v2021.2,
InspectCode automatically restores NuGet packages and builds a solution before
starting its analysis. If this behavior is undesired, use the option
--no-build to disable restoring NuGet packages and building the solution.
Free 30-day trial