ReSharper's context actions save you a lot of typing when you need to introduce minor changes to
Change access modifiers, generate code that checks for null, convert
— all with a couple of keystrokes.
other supported languages.
Press Alt+Enter over a code element that you want to change, and select a context action
As soon as a context action becomes available for the current caret position, ReSharper displays the hammer icon to the left of the caret. If there are several contextually available features, which could be a mix of context actions and quick-fixes, the icon of the action with the highest priority is shown. Click the action indicator or press Alt+Enter to see all available actions.
Similar context actions (for example, actions for different access modifiers) are often grouped together. In this case, expand the group using the right arrow to pick the desired action.
Some context actions (Remove #regions, Specify enum member values, Add name to argument, etc.) can be automatically applied in a larger scope: in the current method, class, file, current project or in the whole solution. You can click a small arrow on the right or press the right arrow key on the keyboard to choose where to apply the transformation.
ReSharper also provides quick-fixes, which could be displayed in the drop-down list along with context actions. The difference between these is simple: quick-fixes only appear for highlighted code issues aiming to fix them and hopefully improve your code while context actions represent mini-refactorings, which simply change the code.
It is important to note that quick-fixes have higher priority, so if there are any quick-fixes at your caret, you have to press Alt+Enter to see if there are any context actions.
With ReSharper, you don't have to type anything to check a parameter for null — just press Alt+Enter and ReSharper will generate the whole null-checking routine for you.
Optionally, if you use
annotations in your
project, the parameter is marked with the
[NotNull] attribute so that ReSharper will warn you about any invocations
the method with null for this parameter.
In this example, you can see how ReSharper's context actions help you quickly convert a
foreach loop and to a lambda expression.
This is the opposite of ReSharper's famous quick-fix that converts loops into LINQ statements.
Some context actions are more like refactorings — they automate complex code transformations while preserving the logic.
In this example, ReSharper helps you transform an iterator with
yield return statements into code that creates, fills up, and returns a
If you need to add a condition to the initialization of an existing local variable, this context action will help you quickly detach the initialization. Even if the variable is implicitly typed, ReSharper will automatically calculate the correct type and use it in the declaration.
With this context action, you can quickly swap the branches of an
ReSharper will make sure that the condition, however complex, is properly negated
so that the logic stays unchanged.
Whatever syntax is used for a delegate (anonymous method or lambda expression), ReSharper's context actions let you change the syntax in a couple of keystrokes, without rewriting the code by hand.
This context action lets you create a method overload that uses a default value for the selected parameter, and again, all without typing anything.
The action is also available in C# and TypeScript.
In XML-like languages, ReSharper's context actions help you streamline routine editing procedures of expanding/collapsing empty tags, and converting attributes to tags and back. These actions are available in XML, XAML, ASP.NET, build scripts, HTML, and Resx files.