ReSharper 2020.3 Help

Context Actions


Context actions are code transformations helpers available right in the editor. In contrast to quick-fixes, context actions do not aim to resolve a problem or improve your code, instead, they allow you to quickly introduce minor changes like changing access modifiers, generating code that checks for null, convert 'foreach' to 'for', etc.

ReSharper provides hundreds of context actions in all supported languages. You can find the full list in the Code Editing | Context Actions page of the ReSharper options and in the Context Actions Reference.

Apply context actions

As soon as a context action becomes available for the current caret position, ReSharper displays the corresponding action indicator Themed icon context action screen gray to the left of the caret. Sometimes however, ReSharper provides several contextually available features for the current caret position. In this case, the action indicator corresponding to the action with the highest priority is shown, and all other actions only appear when you expand the action list by clicking on the action indicator or pressing Alt+Enter Context actions have the lowest priority, therefore, they often appear at the bottom of the action list.

Action list

In most cases, a context action is applied immediately. However, some actions require user interaction to choose how exactly they transform your code. In these cases, a Hot Spot Session is deployed in the editor, where you can select one of the suggested values or provide your own values in the active input positions.

For example, here is what happens when you apply the Iterate collection via 'foreach' context action:

Coding assistance context actions foreach 01

After creating the foreach statement, a hot spot session helps you complete editable parameters of the generated statement:

Coding assistance context actions foreach 02

To complete the hot spot session:

  • If ReSharper suggests some values for the current parameter, use Up and Down arrow keys to navigate through the list of suggested values, or just type in a desired value.

  • Press Tab or Enter to accept the value and move to the input position of the next parameter. If this is the last parameter, the hot spot session completes and the caret moves to the end position defined for the session.

  • Press Shift+Tab to move the input focus to the input position of the previous parameter.

  • Press Esc to exit the hot spot session. In this case, all session parameters will be initialized with default values.

Configure context actions

By default, most of the context actions are enabled, but you can easily disable those that you consider unhelpful.

  1. Select ReSharper | Options from the main menu or press Alt+R O.

  2. Use the search box in the Options dialog to find specific context action.
    Alternatively, open the Code Editing | Context Actions page and look for the context actions that you want to disable.

  3. Clear the check box next to a context action to disable it.

  4. Click Save in the Options dialog to apply the modifications and let ReSharper choose where to save them, or save the modifications to a specific settings layer using the Save To list. For more information, see Manage and Share ReSharper Settings.

Apply context actions in wider scope

Some context actions can automatically find and change similar code items in a larger scope - in the current file, in the current project or in the whole solution. These context actions work the same as Fix in Scope. For example, you can move all types from the current file to new matching files:

Applying context action in a wider scope

The full list of context actions that can be applied in wider scopes includes:


  • Add another accessor

  • Add block braces to switch section statements

  • Add deconstruct pattern component name

  • Add name to argument

  • Add tuple component name

  • Convert explicit to implicit implementation

  • Convert expression body member to statement body

  • Convert 'if' statement to 'switch' expression

  • Convert 'if' statement to 'switch' statement

  • Convert implicit to explicit interface implementation

  • Convert integer literal to binary form

  • Convert integer literal to hexadecimal form

  • Convert integral literal to decimal form

  • Convert string interpolation to 'string.Format' call

  • Convert switch expression to conditional ?: expression(s)

  • Converts member value check expression to recursive pattern

  • Create explicit property declaration for positional parameter

  • Fully qualify reference to type, static member or namespace

  • Include member access into object pattern

  • Insert digit separators in integer literal

  • Insert digit separators in real literal

  • Insert generic method invocation type arguments

  • Invoke extension method as static

  • Join attributes into single section

  • Merge sequential checks into null-propagating expression

  • Merge sequential pattern checks into complex pattern-matching

  • Move type to another file to match its name

  • Qualify static members imported via 'using static' directive

  • Remove #region, #endregion directives (see Add and Remove #region Blocks)

  • Remove argument name

  • Remove digit separators from numeric literal

  • Remove redundant parenthesis (see Code Syntax Style: Optional Parentheses)

  • Remove tuple component name

  • Replace '?:' conditional operator with null-propagating expression

  • Replace array initializer with expression

  • Replace auto-property with property and backing field

  • Replace explicit type specification with 'var'

  • Replace null-propagating expression with '?:' conditional operator

  • Replace separate deconstruction declarations with single declaration

  • Replace 'var' with explicit type declaration

  • Specify enum member values

  • Split attributes into separate sections

  • Split null-propagating expression into sequential checks

  • Split recursive pattern into several consecutive checks

  • Use explicit discard declaration

  • Use implicit discard declaration

  • Use separate declarations in deconstruction declaration/patterns

  • Use string interpolation


  • Move type to another file to match its name


  • Use string interpolation

This feature is supported in the following languages and technologies:

Language: C#Language: VB.NETLanguage: C++Language: HTMLLanguage: ASP.NETLanguage: RazorLanguage: JavaScriptLanguage: TypeScriptLanguage: CSSLanguage: XMLLanguage: XAMLLanguage: ResxLanguage: Build ScriptsLanguage: ProtobufLanguage: JSON
Feature is available in C#Feature is available in Visual Basic .NET Context actions in C++Feature is available in HTMLFeature is available in ASP.NETFeature is available in RazorFeature is available in JavaScriptFeature is available in TypeScriptFeature is available in CSSFeature is available in XMLFeature is available in XAMLFeature is available in Resource filesFeature is available in build script files Feature is not available in ProtobufFeature is available in JSON

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

Last modified: 08 March 2021