{"id":558551,"date":"2025-04-10T17:51:03","date_gmt":"2025-04-10T16:51:03","guid":{"rendered":"https:\/\/blog.jetbrains.com\/?post_type=dotnet&#038;p=558551"},"modified":"2025-04-22T09:44:51","modified_gmt":"2025-04-22T08:44:51","slug":"csharp-language-support-in-resharper-and-rider-2025-1","status":"publish","type":"dotnet","link":"https:\/\/blog.jetbrains.com\/zh-hans\/dotnet\/2025\/04\/10\/csharp-language-support-in-resharper-and-rider-2025-1","title":{"rendered":"C# Language Support in ReSharper and Rider 2025.1"},"content":{"rendered":"\n<p>Our release for ReSharper and Rider 2025.1 is just around the corner, and we have lots of exciting features shipping for the current and next version of C#! This will be a really long post (blame our awesome devs!), so make sure to use the table of contents on the right. Oh, and of course\u2026<\/p>\n\n\n<div class=\"buttons\">\n<div class=\"buttons__row\"><!--<a href=\"https:\/\/www.jetbrains.com\/rider\/download\/\" class=\"btn\" target=\"\" rel=\"noopener\">Download Rider 2025.1<\/a> <a href=\"https:\/\/www.jetbrains.com\/resharper\/download\/\" class=\"btn\" target=\"\" rel=\"noopener\">Download ReSharper 2025.1<\/a> --><a class=\"btn\" href=\"https:\/\/www.jetbrains.com\/rider\/download\/\" target=\"_blank\" rel=\"noopener\">Download Rider 2025.1 <\/a> <a class=\"btn\" href=\"https:\/\/www.jetbrains.com\/resharper\/download\/\" target=\"_blank\" rel=\"noopener\">Download ReSharper 2025.1<\/a><\/div>\n<\/div>\n\n\n<p>For many of the inspections and quick fixes discussed in this post, we recommend using either <a href=\"https:\/\/www.jetbrains.com\/help\/rider\/Inspecting_Code_in_Specific_Scope.html\" target=\"_blank\" rel=\"noopener\"><em>find in scope<\/em><\/a> or <a href=\"https:\/\/www.jetbrains.com\/help\/rider\/Code_Analysis__Fix_in_Scope.html\" target=\"_blank\" rel=\"noopener\"><em>fix in scope<\/em><\/a> to effectively use them in your codebases. Now, let&#8217;s talk about new features!<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Structured Logging Support<\/h2>\n\n\n\n<p>In ReSharper and Rider 2025.1, we enhanced support for structured and <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/core\/extensions\/high-performance-logging\" target=\"_blank\" rel=\"noopener\">high-performance logging<\/a> using the <code>Microsoft.Extensions.Logging<\/code> APIs. Similar to how formatting arguments are highlighted in <code>string.Format<\/code> using the <code>{0}<\/code> syntax, we now highlight the corresponding type arguments in the <code>Logger.Define<\/code> and <code>LoggerMessageAttribute<\/code> API. Additionally, missing type arguments are now reported with diagnostics to catch issues early, along with quick-fixes and context actions to add or remove them as needed:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/structured-and-high-performance-logging-support.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/structured-and-high-performance-logging-support.gif\"\n        alt=\"Structured and High-Performance Logging Support\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Structured and High-Performance Logging Support<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>String Construction Context Actions<\/b><\/h2>\n\n\n\n<p>Our .NET IDEs offer a wide range of suggestions and context actions for working with C# string literals, interpolated strings, <code>string.Format<\/code>, and <code>StringBuilder<\/code> constructs. You can convert nearly any string-related expression into various other forms to enhance readability or to better parameterize string construction.<\/p>\n\n\n\n<p>However, some conversion directions were still missing. For example, while it&#8217;s been easy to convert a concatenated string like <code>\"Id = \" + someId<\/code> into either an interpolated string <code>$\"Id = {someId}\"<\/code> or a format string <code>string.Format(\"Id = {0}\", someId)<\/code>, there hasn&#8217;t been a way to reverse this \u2014 i.e., to convert interpolated or formatted strings back into concatenation. In certain scenarios, such a transformation can actually result in more concise or readable code:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/convert-interpolation-to-concatenation-context-action.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/convert-interpolation-to-concatenation-context-action.gif\"\n        alt=\"Convert Interpolation to Concatenation Context Action\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Convert Interpolation to Concatenation Context Action<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Implicit Usings Refactoring<\/h2>\n\n\n\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/welcome-to-csharp-10\/#global-and-implicit-usings\" target=\"_blank\" rel=\"noopener\"><em>Implicit usings<\/em><\/a> simplify your project by automatically including a set of commonly used namespaces, reducing clutter and improving readability. However, there might be scenarios where you prefer explicit control over your namespace imports \u2014 for example, to ensure clarity about exactly which namespaces are available or to improve compatibility with certain tooling and team conventions.<\/p>\n\n\n\n<p>ReSharper and Rider 2025.1 introduce a convenient action that allows you to easily toggle <em>implicit usings<\/em> on or off for your project. When enabling <em>implicit usings<\/em>, ReSharper automatically removes redundant explicit <code>using<\/code> directives from your source files, streamlining your codebase. Conversely, disabling <em>implicit usings<\/em> will explicitly add the necessary namespaces into your files, ensuring your code remains compilable and readable without any manual adjustments:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/toggle-implicit-usings-context-action.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/toggle-implicit-usings-context-action.gif\"\n        alt=\"Toggle Implicit Usings Context Action\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Toggle Implicit Usings Context Action<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Improved Multiline To-Do Comments<\/b><\/h2>\n\n\n\n<p>In the previous release, we introduced support for multiline to-do comments, where subsequent lines were considered part of the same item based on their indentation. In the 2025.1 release, we&#8217;ve enhanced this feature by making indentation optional. Now, lines following a to-do comment are automatically treated as part of the same item, even without indentation, making multiline comments more intuitive and seamless. However, if indentation is used, it will be strictly enforced:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/improved-multiline-to-do-comments.png\"\n        alt=\"Improved Multiline To-Do Comments\"\n        width=\"660\"\/>\n   <figcaption class=\"wp-element-caption\">Improved Multiline To-Do Comments<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Language Injection in Return Values<\/b><\/h2>\n\n\n\n<p>Language injection made its debut in ReSharper around 10 years ago with <a href=\"https:\/\/blog.jetbrains.com\/dotnet\/2014\/10\/27\/regular-expression-support-in-resharper-9\/\">support for regular expressions<\/a>. Since then, it has been <a href=\"https:\/\/blog.jetbrains.com\/dotnet\/2017\/03\/21\/language-injections-rider\/\">brought to Rider, expanded to other languages<\/a>, and <a href=\"https:\/\/blog.jetbrains.com\/dotnet\/2023\/01\/12\/language-injection-improvements-in-rider-2022-3\/#better-with-c-11\">updated to work with new language and runtime features<\/a>.<\/p>\n\n\n\n<p>Previously, the <code>LanguageInjection<\/code> attribute (from <a href=\"https:\/\/blog.jetbrains.com\/dotnet\/2018\/05\/03\/what-are-jetbrains-annotations\/\"><code>JetBrains.Annotations<\/code><\/a>) could only be applied to parameters, fields, and properties. Now you can annotate methods to specify that their returned strings represent an embedded code of another language:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/language-injection-in-return-values.png\"\n        alt=\"Language Injection in Return Values\"\n        width=\"660\"\/>\n   <figcaption class=\"wp-element-caption\">Language Injection in Return Values<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Redundant Duplicated Code<\/h2>\n\n\n\n<p>In the previous two versions, we introduced inspections for more specific scenarios of code duplication \u2014 <a href=\"https:\/\/blog.jetbrains.com\/dotnet\/2024\/08\/07\/escape-character-extract-common-code-params-modifier-out-vars-csharp-language-support-in-2024-2\/#extract-common-code\">common code in <code>if<\/code> and <code>switch<\/code> statements<\/a> and <a href=\"https:\/\/blog.jetbrains.com\/dotnet\/2024\/11\/12\/csharp-language-support-in-resharper-and-rider-2024-3\/#merge-switch-case-sections\">duplicated <code>switch<\/code> section bodies<\/a>. In this 2025.1 release, we deliver three new inspections to help you eliminate unintentional duplications and improve readability and maintainability in your codebase.<\/p>\n\n\n\n<p>Our first inspection detects duplicated statements that appear both within conditional branches of&nbsp;<code>if<\/code>&nbsp;and&nbsp;<code>switch<\/code>&nbsp;statements ending with jump statements and again immediately afterward:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/duplicated-statements-in-conditional-branches-inspection-and-quick-fix.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/duplicated-statements-in-conditional-branches-inspection-and-quick-fix.gif\"\n        alt=\"Duplicated Statements in Conditional Branches Inspection and Quick-Fix\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Duplicated Statements in Conditional Branches Inspection and Quick-Fix<\/figcaption>\n<\/figure>\n\n\n\n<p>Another inspection detects redundant arms in switch expressions \u2014 specifically, arms that return the same value as the default one. Removing these redundancies simplifies your code and improves readability:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/redundant-switch-expression-arms-inspection-and-quick-fix.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/redundant-switch-expression-arms-inspection-and-quick-fix.gif\"\n        alt=\"Redundant switch Expression Arms Inspection and Quick-Fix\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Redundant switch Expression Arms Inspection and Quick-Fix<\/figcaption>\n<\/figure>\n\n\n\n<p>The last inspection detects when multiple <code>if<\/code> branches execute identical code and provides a handy quick-fix to merge them:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/duplicated-if-bodies-inspection-and-quick-fix.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/duplicated-if-bodies-inspection-and-quick-fix.gif\"\n        alt=\"Duplicated if Bodies Inspection and Quick-Fix\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Duplicated if Bodies Inspection and Quick-Fix<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Misuse of CancellationToken<\/h2>\n\n\n\n<p>When working with asynchronous methods, it&#8217;s common to pass a <code>CancellationToken<\/code> through parameters of local functions or lambda expressions. Accidentally using a method-level token instead of a more specific, locally scoped one can lead to unintended behavior, such as tasks not being canceled when expected.<\/p>\n\n\n\n<p>ReSharper and Rider 2025.1 introduce a new inspection that detects when a broader-scoped cancellation token is mistakenly used instead of a more appropriate local token available within a local function or lambda. You can choose from two corresponding quick-fixes to either a) replace the mistakenly used token with the correct local token, or b) link both tokens into one using <code>CancellationTokenSource.CreateLinkedTokenSource<\/code>:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/possibly-mistaken-use-of-cancellationtoken-inspection.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/possibly-mistaken-use-of-cancellationtoken-inspection.gif\"\n        alt=\"Possibly Mistaken Use of CancellationToken Inspection\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Possibly Mistaken Use of CancellationToken Inspection<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Injection Postfix Template<\/b><\/h2>\n\n\n\n<p>Primary constructors in C# 12 greatly simplify constructor dependency injection patterns. You only need to mention a dependency once in the constructor parameter list, and it automatically becomes available across all instance members of the class without the need to define and assign a field explicitly.<\/p>\n\n\n\n<p>In ReSharper and Rider 2025.1, we introduce a new <code>inject<\/code> postfix template available for type names. When you realize you need to add a dependency on <code>IService<\/code>, select it from the completion list, append <code>.inject<\/code>, and hit your completion key:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/inject-postfix-template.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/inject-postfix-template.gif\"\n        alt=\"Inject Postfix Template\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Inject Postfix Template<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Transform Parameters Refactoring<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/www.jetbrains.com\/help\/rider\/Refactorings_Transform_Parameters.html\" target=\"_blank\" rel=\"noopener\">transform parameters refactoring<\/a> makes it easy to change a method&#8217;s signature by modifying its parameters \u2014 for example, removing <code>out<\/code> parameters, wrapping them in a tuple or a new class, and more \u2014 while automatically updating all usages of the method across your solution.<\/p>\n\n\n\n<p>With ReSharper and Rider 2025.1, we reworked the refactoring to support modern language features (including tuple types, record classes, and primary constructors), treat tuple elements as multiple return values, transform <code>ref<\/code> parameters into both input and output values, and handle lots of deconstruction usages. Bring up the dialog, select the parameters you want to transform, and choose your desired target types:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/transform-parameters-refactoring-dialog.png\"\n        alt=\"Transform Parameters Refactoring Dialog\"\n        width=\"686\"\/>\n   <figcaption class=\"wp-element-caption\">Transform Parameters Refactoring Dialog<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Context Highlighters for Extended Types<\/b><\/h2>\n\n\n\n<p>One of the very subtle features in ReSharper and Rider is the <a href=\"https:\/\/www.jetbrains.com\/help\/rider\/Coding_Assistance__Matching_Delimiters.html\" target=\"_blank\" rel=\"noopener\">highlighting of matching code elements<\/a> (for instance, check out <em>Matching of control flow keywords<\/em>). From 2025.1, we will help you to visually identify members that extend the base class or implement some concrete interface type. Just place the caret over the type name in the base types clause:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/context-highlighters-for-extended-and-implemented-members.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/context-highlighters-for-extended-and-implemented-members.gif\"\n        alt=\"Context Highlighters for Extended and Implemented Members\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Context Highlighters for Extended and Implemented Members<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Chop Formatting Context Action<\/b><\/h2>\n\n\n\n<p>Our built-in formatter helps you to align your code with your preferred code formatting style settings. It can be invoked manually, through an <a href=\"https:\/\/www.jetbrains.com\/help\/rider\/Enforcing_Code_Formatting_Rules.html#run-code-cleanup-automatically-on-save\" target=\"_blank\" rel=\"noopener\">\u201con-save\u201d action<\/a>, or <a href=\"https:\/\/www.jetbrains.com\/help\/rider\/Enforcing_Code_Formatting_Rules.html#reformat_before_commit\" target=\"_blank\" rel=\"noopener\">before committing changes<\/a>. Sometimes, though, you may want more control without triggering widespread formatting. A new context action lets you apply chop formatting to various C# constructs directly without needing to make a selection:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/chop-parameters-list-context-action.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/chop-parameters-list-context-action.gif\"\n        alt=\"Chop Parameters List Context Action\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Chop Parameters List Context Action<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Modification in Debug.Assert<\/b><\/h2>\n\n\n\n<p>When writing code assertions using APIs like <code>Debug.Assert<\/code>, it&#8217;s easy to forget that these calls are stripped out in <code>RELEASE<\/code> builds. This is because methods marked with attributes like <code>[Conditional(\"DEBUG\")]<\/code> are only compiled when the <code>DEBUG<\/code> symbol is defined in the project. As a result, if the assertion condition includes side effects \u2014 such as assignments or collection mutations \u2014 those side effects will <em>not<\/em> occur in <code>RELEASE<\/code> builds. These conditional side effects are hard to spot and reason about, and they can lead to subtle bugs or unexpected behavior.<\/p>\n\n\n\n<p>Our new 2025.1 code inspection detects and warns you about such cases automatically:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/modifications-in-debugassert-inspection.png\"\n        alt=\"Modifications in Debug.Assert Inspection\"\n        width=\"660\"\/>\n   <figcaption class=\"wp-element-caption\">Modifications in Debug.Assert Inspection<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Inexact Stream Reads<\/b><\/h2>\n\n\n\n<p>A common mistake when working with .NET&#8217;s <code>Stream<\/code> class is misusing the <code>Read<\/code> and <code>ReadAsync<\/code> methods. These methods accept a buffer (an array or a <code>Span&lt;byte&gt;<\/code>) and are often assumed to fill it <em>completely <\/em>\u2014 but they are not guaranteed to do so. Crucially, <code>Stream<\/code> implementations are allowed to return partial data and will report the actual number of bytes read, which may be less than the buffer size. That&#8217;s why it&#8217;s essential to handle the return value from <code>Read<\/code> and <code>ReadAsync<\/code> properly and continue reading until the desired amount of data is received.<\/p>\n\n\n\n<p>Starting with our 2025.1 IDEs, incorrect usage patterns of <code>Read<\/code> and <code>ReadAsync<\/code> are automatically detected, with suggestions to replace them with the safer <code>ReadExactly<\/code> API:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/inexact-stream-reads-inspection-and-quick-fix.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/inexact-stream-reads-inspection-and-quick-fix.gif\"\n        alt=\"Inexact Stream Reads Inspection and Quick-Fix\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Inexact Stream Reads Inspection and Quick-Fix<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Tuple Component Names<\/b><\/h2>\n\n\n\n<p>Tuple types allow you to use both explicit and generic component names. Sometimes, it is overlooked that a component can be referenced by its explicit name, e.g., <code>MyComponent<\/code>, rather than <code>ItemN<\/code>. Our new IDE hint and corresponding quick-fix help you to get rid of generic names in favor of explicit names to make your code more readable:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/prefer-explicit-name-for-tuple-component-inspection-and-quick-fix.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/prefer-explicit-name-for-tuple-component-inspection-and-quick-fix.gif\"\n        alt=\"Prefer Explicit Name for Tuple Component Inspection and Quick-Fix\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Prefer Explicit Name for Tuple Component Inspection and Quick-Fix<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Referencing Enum Member Names<\/b><\/h2>\n\n\n\n<p>The <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/operators\/nameof\" target=\"_blank\" rel=\"noopener\"><code>nameof<\/code> operator was introduced in C# 6<\/a> \u2014 another case of \u201c10 years today\u201d!&nbsp;Since then, many have embraced it extensively to reference variable, type, and member names as string constants instead of using magic strings. ReSharper and Rider continue to spot situations [<a href=\"https:\/\/blog.jetbrains.com\/dotnet\/2015\/04\/15\/c-6-0-support-in-resharper-9-1\/\">1<\/a>, <a href=\"https:\/\/blog.jetbrains.com\/dotnet\/2023\/03\/06\/required-keyword-checked-operators-nameof-operator-scope-using-csharp-11-in-rider-and-resharper\/#nameof-operator-scope\">2<\/a>] in which you can make better use of them. Referencing an enum member through <code>ToString<\/code> introduces unnecessary runtime overhead due to reflection and additional processing.<\/p>\n\n\n\n<p>In 2025.1, we are adding a new inspection <em>Use <code>nameof<\/code> expression to reference enum member name<\/em> that targets such cases and provides a quick-fix to convert to <code>nameof<\/code> as a compile-time language feature that is faster, safer, and clearer:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/use-nameof-for-reference-inspection-and-quick-fix.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/use-nameof-for-reference-inspection-and-quick-fix.gif\"\n        alt=\"Use nameof for Reference Inspection and Quick-Fix\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Use nameof for Reference Inspection and Quick-Fix<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Nameof with Unbound Generics<\/b><\/h2>\n\n\n\n<p>Another new feature in C# 14 now allows using the <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/whats-new\/csharp-14#unbound-generic-types-and-nameof\" target=\"_blank\" rel=\"noopener\"><code>nameof<\/code> operator with unbound generics<\/a>. Previously, to get <code>List<\/code> as a compile-time constant, you had to provide generic arguments \u2014 e.g., <code>nameof(List&lt;DontCare&gt;)<\/code> \u2014 even though they are not included in the final name. This friction is now removed, and you can use the open generic as in <code>nameof(List&lt;&gt;)<\/code>.<\/p>\n\n\n\n<p>ReSharper and Rider identify places where generic types in <code>nameof<\/code> operators can be simplified and provide a quick-fix to remove redundancies:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/redundant-type-arguments-in-nameof-inspection-and-quick-fix.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/redundant-type-arguments-in-nameof-inspection-and-quick-fix.gif\"\n        alt=\"Redundant Type Arguments in nameof Inspection and Quick-Fix\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Redundant Type Arguments in nameof Inspection and Quick-Fix<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>First-Class Span Types<\/b><\/h2>\n\n\n\n<p>In recent years, the BCL and many other libraries have extensively adopted <code>Span&lt;T&gt;<\/code> and <code>ReadOnlySpan&lt;T&gt;<\/code> to provide more performant APIs. With C# 14, <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/whats-new\/csharp-14#implicit-span-conversions\" target=\"_blank\" rel=\"noopener\">first-class support for span types is introduced through new implicit conversions<\/a> between <code>ReadOnlySpan&lt;T&gt;<\/code>, <code>Span&lt;T&gt;<\/code>, and <code>T[]<\/code>, which are now applied in more scenarios. This makes working with spans more intuitive and seamless. ReSharper and Rider 2025.1 fully support these updated conversion rules:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/span-type-conversion.png\"\n        alt=\"Span Type Conversion\"\n        width=\"660\"\/>\n   <figcaption class=\"wp-element-caption\">Span Type Conversion<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Simple Lambda Parameters with Modifiers<\/b><\/h2>\n\n\n\n<p>The next C# update <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/whats-new\/csharp-14#simple-lambda-parameters-with-modifiers\" target=\"_blank\" rel=\"noopener\">simplifies writing lambda signatures<\/a>. Previously, using parameter modifiers like <code>ref<\/code>, <code>out<\/code>, <code>in<\/code>, <code>ref readonly<\/code>, or <code>scoped<\/code> in lambdas required explicitly specifying the parameter type \u2014 for no particular reason. Starting with C# 14, this restriction has been lifted, allowing you to use these modifiers without redundant type annotations.<\/p>\n\n\n\n<p>As you&#8217;d expect, ReSharper and Rider 2025.1 offer a quick-fix to remove the now-redundant type specifications:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/redundant-lambda-parameters-inspection-and-quick-fix.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/redundant-lambda-parameters-inspection-and-quick-fix.gif\"\n        alt=\"Redundant Lambda Parameters Inspection and Quick-Fix\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Redundant Lambda Parameters Inspection and Quick-Fix<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Default Literal Suggestions<\/b><\/h2>\n\n\n\n<p>C# is well-known for offering multiple ways to express the same concept (looking at you, null checks!). While flexibility has its merits, this kind of redundancy is generally not a good thing. It&#8217;s exactly why IDE tooling plays a crucial role in helping developers standardize and streamline code \u2014 ensuring consistency and reducing ambiguity.<\/p>\n\n\n\n<p>Using the <code>default<\/code> literal in non-generic contexts to represent trivial values like <code>0<\/code> or <code>false<\/code> can make code harder to reason about. ReSharper and Rider now help you catch such cases and offer recommendations to clarify the intent:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default aligncenter\">\n    <img\n        src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/default-literal-inspection-and-quick-fix.jpg\"\n        data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/default-literal-inspection-and-quick-fix.gif\"\n        alt=\"Default Literal Inspection and Quick-Fix\"\n        width=\"660\"\/>\n    <figcaption class=\"wp-element-caption\">Default Literal Inspection and Quick-Fix<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Wow \u2014 that was a lot to cover! One thing&#8217;s clear: our team has poured serious effort into not just flashy new language features but also refining older ones, making them shine in fresh ways.<\/p>\n\n\n\n<p>We&#8217;d love to hear from you. Do you spot any issues or have ideas for ReSharper and Rider <code>vNextNext<\/code>? Drop them in the comments!<\/p>\n\n\n\n<!--more-->\n","protected":false},"author":553,"featured_media":558166,"comment_status":"closed","ping_status":"closed","template":"","categories":[4992,1401],"tags":[158,211,737,1938,756,3912],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/dotnet\/558551"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/dotnet"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/types\/dotnet"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/users\/553"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/comments?post=558551"}],"version-history":[{"count":10,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/dotnet\/558551\/revisions"}],"predecessor-version":[{"id":562579,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/dotnet\/558551\/revisions\/562579"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/media\/558166"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/media?parent=558551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/categories?post=558551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/tags?post=558551"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/cross-post-tag?post=558551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}