ReSharper 8.0 Web Help

ReSharper | Options | Code Editing | C# | Context Actions

By selecting or clearing check boxes in this page, you can compile the list of available Context Actions. When you select a specific context action, you can read its description in the bottom of the page.

ReSharper provides the following context actions for C#:

Name Description
Add another accessor Adds second accessor to an event or a property.
Add exception xml comment tag Add exception xml comment tag.
Add explicit name of anonymous property Adds explicit name specification to anonymous type property declaration.
Add name to argument Adds name to selected argument.
Add new format item Adds new format item to format string and new argument to Format method invocation
Annotate method with 'value can be null' attribute Annotates a method with 'value can be null' attribute. The attribute can be configured via external annotations. For more information, see External Annotations.
Annotate method with 'value cannot be null' attribute Annotates a method with 'value cannot be null' attribute. The attribute can be configured via external annotations.
Assert reference is not null Adds assert statement that performs null reference check for a variable at the caret. Assert expression can be customized by changing 'asrtn' Live Template
'catch' to 'catch(Exception)' Converts catch to catch(System.Exception).
'catch(Exception)' to 'catch' Converts catch(System.Exception) to catch.
Change member visibility Available on an access modifier keyword and allows changing access rights of a declaration.
Check array index value Checks index value for arrays
Check collection index value Checks index value for collections and lists
Check dictionary key value Checks key value for dictionaries
Check if parameter is null Checks function parameter for null.
Check if reference is not null Puts the current statement under an 'if' statement that performs null reference check for a variable at the caret.
Check if variable is null Checks variable for null.
Check string index value Checks index value for strings
Check StringBuilder index value Checks index value for the StringBuilder
Compute constant value Computes value of the current experssion and replace it (e.g. 1 + 1 replaced by 2).
Convert '==' to 'Equals' Converts usage of equality operator ('==') to a call to object.Equals method.
Convert anonymous method to lambda Converts anonymous method to lambda
Convert coalescing operator to ternary Converts null coalescing operator to ternary conditional operator.
Convert 'Equals' to '==' operator Converts a call to the static object.Equals method into usage of equality ('==') or inequality ('!=') operator.
Convert explicit to implicit implementation Converts explicit implementation of an interface method to implicit one.
Convert 'foreach' to 'for' loop Works on 'foreach' statements executed on a collection that allows direct access to its elements by index. It converts such 'foreach' statement to 'for' statement.
Convert 'if' statement to 'switch' statement Works on 'if' statements that compare value of an expression with one or more constants. It converts such 'if' statements into a single 'switch' statement.
Convert 'if' statement to ternary expression Works on 'if' statement that returns value or performs assignment inside each branch. It converts the statement to a ternary expression ('x ? a : b')
Convert implicit to explicit interface implementation Converts implicit implementation of an interface member to explicit one.
Convert instance 'Equals' to static 'Equals' Converts a call to instance Equals method into usage of equality ('==') or inequality ('!=') operator.
Convert lambda body with single return statement to expression Converts return statement of lambda body to expression
Convert lambda expression body to body with single return statement Converts expression of lambda body to return statement
Convert lambda to anonymous delegate Converts lambda to anonymous method.
Convert LINQ to code Converts LINQ to code
Convert LINQ to method chain Converts LINQ query to extension methods call.
Convert method group to anonymous method Converts method group to anonymous method.
Convert method group to lambda Converts method group to lambda expression.
Convert 'switch' statement to 'if' statement Converts 'switch' statements into one or multiple nested 'if' statements each checking for individual value.
Convert ternary expression to 'if' statement Converts ternary expression whose value is returned or assigned to an 'if' statement.
Convert ternary to coalescing operator Converts ternary conditional operator comparing value with null to coalescing operator.
Convert to dec Converts numeric value from hexadecimal to decimal.
Convert to hex Converts numeric value from decimal to hexadecimal.
Convert to regular string Converts verbatim string @"" to regular string "".
Convert to verbatim string Converts regular string "" to verbatim string @"".
Copy comments from base Copies comments from base to overriding members/types
Create derived type Creates class that implements interface or inherits class.
Create event invocator Creates event invocator.
Create overload with selected argument's type Available on method invocation, creates overload with selected argument's type
Create overload without parameter Creates overload without given parameter. Calls current method.
Create return from expression statement Creates return statement with value that is taken as an expression statement
Extract anonymous method to method of the containing type Extracts anonymous method as a private method of the containing type.
Extract lambda to method of the containing type Extracts lambda as a private method of the containing type.
Flip an invocation expression Flips the current invocation expression e.g. left.Equals(right) to right.Equals(left).
Flip an operator arguments Flips left and right arguments for selected operator e.g. null == list to list == null.
Flip an relational expression Flips the current relational expression e.g. list.Cont > 1 to list.Cont < 1.
Implement abstract member Works on an interface member or an abstract member. Searches for classes where this member needs to be implemented and allows to implement it in one of them.
Implement custom event accessors Adds placeholders for custom implementation of 'add' and 'remove' methods for an event.
Implement INotifyPropertyChanged pattern Creates method to invoke PropertyChanged event with string literal parameter and adds ReSharper annotation to enable identifying this method by INotifyPropertyChanged support
Initialize auto-property from constructor parameter Optionally creates and initializes auto-property from constructor parameter.
Initialize field from constructor parameter Optionally creates and initializes field from constructor parameter
Inline as anonymous type action Replaces usages of the type in the method with anonymous type usages.
Insert anonymous method signature Adds proper signature to parameterless declaration of an anonymous method.
Insert inferred type arguments Inserts method's inferred type arguments.
Introduce variable from expression statement Introduces variable from expression statement
Invert 'if' statement Inverts guard condition of an 'if' statement and swaps the branches' code accordingly.
Invert logical expression Invert logical expression
Invert relational operator and negate condition Replaces a conditional expression with an inverted negative, e.g. converts list.Cont > 1 to !(list.Cont <=1).
Invert ternary condition Inverts condition and swaps branches of a ternary expression.
Invoke as static method Changes invocation syntax from extension method to static method.
Iterate via 'foreach' Works on an expression of System.ICollection type or other expression whose value can be iterated with 'foreach' statement. Generates a 'foreach' statement iterating the expression.
Join local variable declaration and assignment Works on an assignment to a variable that was declared without initializer. Moves the declaration to the current point and merges it with the assigment.
Join string literals Concatenates two string literals into one.
Make abstract member virtual Makes abstract member virtual.
Make method partial Converts private void method to partial method defining declaration.
Match file name with type name Renames current file to match the name of the only top-level type declared therein.
Merge nested 'if' statements Merges two nested 'if' statements to a single 'if' statement that checks conjunction of the original conditions.
Merge partial method declarations Merges all declarations of a partial method into single declaration.
Merge partial type declarations Merges all declarations of a partial type into single declaration.
Move concatenation argument to formatting argument Moves concatenation argument to new argument of format method and injects a format item to format string argument.
Move declaration(s) to another type part Moves selected declarations range or a single declaration (if invoked without selection on declaration name) to another type part of a partial type.
Move initialization to constructor(s) Works on fields initialized in the declaration. It moves the initialization to constructors.
Move to outer scope Moves variable to outer scope.
Move type to another file to match its name Moves current type to another file so that its name matches the name of the type.
Negate logical expression Negates logical expression
Notify property changes Adds call to the notification method
Override virtual member Works on a virtual member. Searches for classes where this member can be overriden and allows to override it in one or all of them.
Put inside 'using' construct Converts variable declaration of type that implements the System.IDisposable interface into 'using' statement. This is useful for enforcing lifetime for disposable objects.
Remove #region, #endregion directives Removes region and corresponding endregion pair of directives
Remove braces Removes unneccessary braces around one or more statements in the code
Remove format item Removes format string item and proper formatting method argument
Remove redundant parenthesis Removes parenthesis in case they are redundant
Replace array initializer with creation expression Replaces array initializer with array creation expression.
Replace ArrayList with List<T> Replaces ArrayList type of a local variable with generic List<T> type where T is guessed
Replace auto-property with backing field Replaces auto-property with property that utilizes backing field.
Replace backing field with auto-property Replaces property that utilizes backing field with auto-property.
Replaces explicit type specification with 'var' Replace type with 'var'.
Replaces 'var' with explicit type declaration Replace 'var' with explicit type declaration.
Reverse assignment statement Reverses source and destination parts of an assignment statement.
Specify array type explicitly Adds explicit type specification to array creation expression.
Split declaration list Works on variable declaration statement that declares multiple variables. It splits such statement into multiple statements each declaring a single variable.
Split 'if' with '&&'-condition into nested 'if'-statements Works on an 'if' statement, which condition is a conjunction ('&&') of two simpler conditions. It converts the 'if' statement into two nested 'if' statements.
Split 'if' with '||'-condition into assigment to temporary variable and two 'if'-statements Works on an 'if' statement, which condition is a disjunction ('||') of two simpler conditions. It converts the 'if' statement into an assignment to a temporary variable and an two 'if' statements.
Split local variable declaration and assignment Moves variable initializer from declaration statement to separate assignment statement.
Split 'return' with '&&'-condition into guarding 'if' and 'return' Works on a 'return' statement, which condition is a conjunction ('&&') of two simpler conditions. It converts the 'return' statement into a guarding 'if' statement and a 'return'.
Split 'return' with '||'-condition into assigment to temporary variable, 'if'-statement and 'return' Works on an 'return' statement, which condition is a disjunction ('||') of two simpler conditions. It converts the 'return' statement into an assignment to a temporary variable, 'if' statement and 'return' statement.
Split string literal Splits string literal into two literals.
Splits variable into several ones Replaces original variable with several ones declared in inner blocks of the current block.
Surround with "" Creates string literal of selection text.
Surround with format Surrounds string with string.Format() call.
To abstract/To virtual/To non-abstract/To non-virtual Makes type memeber abstract, virtual or non-abstract and non-virtual.
To assignment statements Replaces initializer with series of assignments.
Use Add() method calls Replaces collection or collection element initializer with series of Add method calls.
Use 'as' and check for null Converts 'if(a is B) {}' to 'var b = a as B; if(b != null) {}' and updates usages
Use collection initializer Replaces series of Add() method calls with collection initializer.
Use format string Converts concatenation of a few strings and other objects to the use of string.Format method.
Use object initializer Replaces series of assignments with object initializer.
Use System.Environment.NewLine Use System.Environment.NewLine instead of "\n", "\r" or "\r\n" literal.
Use System.String.Empty Use System.String.Empty instead of "" literal.

Note

ReSharper's settings are saved in settings layers that enable you to have different settings for different solutions as well as to share your settings with your team. To learn more, study the Managing and Sharing Options section.