ReSharper 2016.1 Help

Context Actions for C#

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#:

NameDescription
Add another accessor Adds second accessor to an event or a property.
Add block braces to case statement Adds braces to case labels inside switch statements.
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 argument to interpolation Adds new argument to interpolation and converts string to interpolation if necessary
Add new format item Adds new format item to format string and new argument to Format method invocation For more information, see code analysis and helpers for string literals.
Add specific values to enum members Adds specific values to enum members
Annotate enum members with EnumMemberAttribute Adds EnumMemberAttribute to each enum member
Annotate member with nullability attribute Annotates type member or parameter with nullability attribute. For more information, see annotations in source code.
Annotate members with DataMemberAttribute Adds DataMemberAttribute to all public properties and fields
Annotate methods with OperationContractAttribute Adds OperationContractAttribute to all exposed methods
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 (Exception)' to 'catch' Converts catch(System.Exception) to catch.
'catch' to 'catch (Exception)' Converts 'catch' clause to 'catch (System.Exception)' form.
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 enum parameter is defined by enum type Checks that function parameter is defined by enum type
Check if parameter is an empty collection Checks function parameter for empty collection
Check if parameter is not valid Checks function parameter for validity
Check if parameter is null Checks function parameter for null.
Check if parameter is null or empty string Checks function parameter for null or empty string
Check if parameter is null or whitespace string Checks function parameter for null or whitespace string
Check if parameter is out of range Checks function parameter for specified range
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 expression and replaces it (e.g. 1 + 1 replaced by 2).
Convert '==' to object.Equals() call Converts usage of equality operator ('==') to a call of 'object.Equals' method.
Convert '==' to object.ReferenceEquals() call Converts usage of equality operator ('==') to a call to 'object.ReferenceEquals' method.
Convert anonymous method to lambda expression Converts anonymous method expression to lambda expression.
Convert auto-property to property with default body Convert auto-property to property with default body For more information, see using auto-properties
Convert coalescing operator to conditional Converts null coalescing operator to conditional operator.
Convert 'Equals' method call into equality operator usage Converts a call to instance or static '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 expression body member to statement body Converts expression-bodied member declaration to statement-bodied form
Convert expression lambda to statement lambda Converts expression-bodied lambda expression to statement-bodied form
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 '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 iterator to method Converts iterator to method or property with List<T> fill or array return
Convert lambda expression to anonymous method Converts lambda expression to anonymous method expression.
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 'ReferenceEquals' method call into equality operator usage Converts a call to static 'ReferenceEquals' method into usage of equality ('==') or inequality ('!=') operator.
Convert statement body member to expression body Converts statement-bodied member declaration to expression-bodied form
Convert statement lambda to expression lambda Converts statement-bodied lambda expression to expression-bodied form
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 foreach statement Converts xs.ForEach(x => ...) calls to regular foreach statament
Convert to hex Converts numeric value from decimal to hexadecimal.
Convert to regular string Converts verbatim string @".." to regular string "..". For more information, see code analysis and helpers for string literals.
Convert to regular string interpolation Converts verbatim string interpolation $@".." to regular $"..". For more information, see code analysis and helpers for string literals.
Convert to string interpolation Converts regular or verbatim string to corresponding string interpolation
Convert to string interpolation Converts string.Format call to string interpolation even in case that could change control flow
Convert to string.Format Converts interpolated string to string.Format invocation
Convert to verbatim string Converts regular string ".." to verbatim string @"..". For more information, see code analysis and helpers for string literals.
Convert to verbatim string interpolation Converts regular string interpolation $".." to verbatim $@"..". For more information, see code analysis and helpers for string literals.
Copy comments from base Copies comments from base to overriding members/types
Create another part of a class or a struct Marks the type as partial if necessary and creates new part in new file
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 Creates return statement with value that is taken as an expression statement
Evaluate expression Evaluates simple expression and replaces it with evaluated value
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.
Fix regular expression Fix invalid characters in regular expression For more information, see regular expressions assistance.
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 operands for selected operator e.g. 'null == list' to 'list == null'.
Flip an relational expression Flips the current relational expression e.g. 'list.Count > 1' to 'list.Count < 1'.
Fully qualify reference to type, static member or namespace Insert full qualification for reference to type, static member or namespace
Generate extension method to check whether enum value contains specified flag Generates extension method to check whether enum value contains specified flag
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
Import static members of type with 'using static' directive in file Imports static members of type with C# 6.0 'using static' directive in file
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 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 attributes Rearranges attributes into single sections
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 assignment.
Join string literals Concatenates two string literals into one.
Make comparison case-insensitive Converts comparison to string.Compare invocation
Make method partial Converts private void method to partial method defining declaration.
Make regular expression here Make string literal by regular expression
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.
Merge sequential checks by use of conditional access expression Merge sequential null or type checks by use of C# 6.0 conditional access expression (null-propagation operator)
Move assignment in constructor to initializer Moves assignment from constructor to field/event/property initializer
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) Moves field/event/property initializers to constructor(s)
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 For more information, see inotifypropertychanged support.
Override virtual member Works on a virtual member. Searches for classes where this member can be overridden and allows to override it in one or all of them.
Pass string interpolation Passes string interpolation instead of formatting method call
Pass string.Format Passes string.Format to formatting method call
Pull expression from variable initializer Pull variable initializer expression to it's usage(s)
Push expression to variable initializer Push equavalent variable usage expression(s) to it's initializer
Put inside 'using' statement Converts variable declaration of type that implements the 'System.IDisposable' interface into 'using' statement. This is useful for enforcing lifetime for disposable objects.
Qualify static members usages imported in scope via 'using static' directive Inserts type qualification for static members usages imported in scope via C# 6.0 'using static' directive
Remove #region, #endregion directives Removes region and corresponding endregion pair of directives For more information, see adding and removing #region blocks.
Remove argument name Removes name from selected argument.
Remove braces Removes unnecessary braces around one or more statements in the code
Remove format item Removes format string item and proper formatting method argument For more information, see code analysis and helpers for string literals.
Remove redundant parenthesis Removes parenthesis in case they are redundant
Remove regular expression Remove regular expression from string literal
Replace array initializer with creation expression Replaces array initializer with array creation expression.
Replace auto-property with property and backing field Replaces auto-property with property that utilizes backing field. For more information, see using auto-properties
Replace conditional access expression with conditional ternary operator Replaces use of C# 6.0 conditional access expression (null-propagation operator) with conditional expression ('?:' operator)
Replace conditional access expression with 'if' statement Replace conditional access expression (null-propagation) with 'if' statement
Replace conditional access expression with ordinary access Replaces C# 6.0 conditional member access/invocation (?.) or conditional indexer access (?[]) with ordinary access
Replace conditional ternary operator with conditional access expression Replaces use of C# 6.0 conditional access expression (null-propagation operator) with conditional expression ('?:' operator)
Replace direct cast expression with safe cast using 'as' expression Replace direct cast expression with safe cast using 'as' expression.
Replace explicit type specification with 'var' when inferred type would change Allows to replace type with 'var' even in the case when doing so would change the type of the variable.
Replace explicit type specification with 'var' when inferred type would remain the same Replace type with 'var'.
Replace 'if' statement with conditional access expression(s) Replace 'if' statement with conditional access expressions (null-propagation)
Replace logical expression with equal expression Invert logical expression with equal expression
Replace member access with conditional access expression Replaces member access/invocation or indexer access with C# 6.0 conditional access expression (null-propagation operator)
Replace property with backing field with auto-property Replaces property that utilizes backing field with auto-property. For more information, see using auto-properties
Replace safe 'as' cast expression with direct cast expression Replace safe 'as' cast expression with direct cast expression.
Replace usages of extension methods like .IfNotNull(x => x.Property) with condtional access expression Replace usages of extension methods like .IfNotNull(x => x.Property) with C# 6.0 condtional access expression (null-propagation operator)
Replace '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 attributes Rearranges attributes into separate sections
Split conditional access expression into sequental null-checks Split C# 6.0 conditional access expression (null-propagation) into sequential null-checks
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 two 'if'-statements Works on an 'if' statement, which condition is a disjunction ('||') of two simpler conditions. It converts the 'if' statement into two 'if' statements with equal bodies.
Split local variable declaration and assignment Moves variable initializer from declaration statement to separate assignment statement.
Split 'return' statement of boolean value to 'if' statement Works on an 'return' statement, which value is of boolean type. It converts the 'return' statement into 'if' statement with a two'return' statements, returning 'true' and 'false' values.
Split 'return' with '&&'-condition into guarding 'if' and 'return' Works on a 'return' statement, which value 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 assignment to temporary variable, 'if'-statement and 'return' Works on an 'return' statement, which value 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/virtual/non-abstract/non-virtual member Makes type member abstract, virtual or non-abstract and non-virtual.
To assignment statements Replaces initializer with series of assignments.
To LINQ to JSON Convert JSON string to JSON.NET object
To LINQ to XML Convert XML string to LINQ to XML object
To precompiled Regex Introduce field to Regular Expression object For more information, see regular expressions assistance.
To string literal Convert invalid character to string literal
Uncomment Uncomments code block For more information, see commenting and uncommenting code.
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. For more information, see code analysis and helpers for string literals.
Use object initializer Replaces series of assignments with object initializer.
Use string interpolation Converts concatenation of a few strings and other objects to the use of string interpolation.
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.
Validate regular expression Open manager to validate regular expression For more information, see regular expressions assistance.

See Also

Last modified: 19 August 2016