ReSharper 2017.1 Help

Context Actions for C#

ReSharper provides the following context actions for C#:

NameDescription
Add <exception> tag to XML documentation Add <exception> tag to XML documentation.
Add <inheritdoc/> tag to XML documentation Adds <inheritdoc/> so that the XML documentation is inherited
Add another accessor Adds second accessor to an event or a property.
Add block braces to switch section statements Adds braces to switch section statements
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 string formatting method argument Adds new format item to format string and corresponding argument to formatting method invocation For more information, see code analysis and helpers for string literals.
Add string interpolation argument Adds new argument to string interpolation expression. Available over ordindary string literals as well
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
Change member visibility Available on an access modifier keyword and allows changing access rights of a declaration.
Check all string parameters for nulls or empty strings Checks all string parameters for nulls or empty strings
Check all string parameters for nulls or whitespace strings Checks all string parameters for nulls or whitespace strings
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 every parameter for null Checks all function parameters for null.
Check if enum parameter is defined by enum type Checks that function parameter is defined by enum type
Check if numeric parameter is out of range Checks numeric parameter for specified range
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 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 string parameter is null or empty string Checks string parameter for null or empty string
Check if string parameter is null or whitespace string Checks string parameter for null or whitespace string
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 '?:' conditional expression to 'if' statement Converts conditional expression whose value is returned or assigned to an 'if' statement.
Convert '==' operator to 'object.Equals()' call Converts usage of equality operator ('==') to a call of 'object.Equals' method.
Convert '==' operator 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 'catch (Exception)' clause to 'catch' Converts 'catch (System.Exception)' clause into 'catch' form.
Convert 'catch' clause to 'catch (Exception)' Converts 'catch' clause into 'catch (System.Exception)' form.
Convert collection initializer into 'Add' method calls Replaces collection initializer with the series of 'Add()' method calls.
Convert 'Equals' method call into '==' 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' method call to 'foreach' statement Converts 'xs.ForEach(x =>...)' calls into regular 'foreach' statament
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 '?:' conditional expression Works on 'if' statement that returns value or performs assignment inside each branch. It converts the statement to a conditional expression ('x ? a: b')
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 implicit to explicit interface implementation Converts implicit implementation of an interface member to explicit one.
Convert integer literal to binary form Converts integer literal to binary form.
Convert integer literal to hexadecimal form Converts integer literal to hexadecimal form.
Convert integral literal to decimal form Converts integer literal to decimal form.
Convert invalid character literal to string Convert invalid character literal into string literal
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 object initializer into assignment statements Replaces object initializer with the series of assignment statements.
Convert 'ReferenceEquals' method call into '==' 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 string comparison to 'string.Equals' call Converts string comparison int 'string.Equals' method call
Convert string interpolation to 'string.Format' call Converts string interpolation expression into corresponding 'string.Format' method call
Convert string literal to string interpolation Converts regular or verbatim string to corresponding kind of string interpolation expression.
Convert 'string.Format' to string interpolation Converts 'string.Format' call to string interpolation (even in case that could change the order of arguments evaluation)
Convert 'switch' statement to 'if' statement Converts 'switch' statements into one or multiple nested 'if' statements each checking for individual value.
Convert to regular string interpolation Converts verbatim string interpolation $@".." to regular $"..". For more information, see code analysis and helpers for string literals.
Convert to regular string literal Converts verbatim string @".." to regular 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.
Convert to verbatim string literal Converts regular string literal ".." to verbatim string @"..". For more information, see code analysis and helpers for string literals.
Copy XML documentation from base member Copies XML documentation from base to overriding members/types
Create another part of a type declaration 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
Delete comment Deletes comment
Encapsulate lazy field Encapsulating lazy field to property if there is no existing one
Evaluate expression Evaluates simple expression and replaces it with evaluated value
Extract anonymous method expression to local function Extracts anonymous method expression into local function in the containing scope.
Extract anonymous method expression to named method Extracts anonymous method expression into private method of the containing type.
Extract lambda expression to local function Extracts lambda expression into local function in the containing scope.
Extract lambda expression to named method Extracts lambda expression into private method of the containing type.
Extract local function to regular method Extracts local function into regular method in the containing type.
Fix invalid escape sequences Fix invalid escapings in string by escaping all characters
Fix invalid regular string Fix invalid characters in string by making it verbatim
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 method to check whether enum 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 with 'using static' directive 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 string interpolation argument Inlines string literal or nested string interpolation into containing interpolated string
Insert anonymous method signature Adds proper signature to parameterless declaration of an anonymous method.
Insert digit separators in integer literal Places digit separators in common places of integer literals: separates thousands in decimal literals, 16-bit words in hexadecimal literals, bytes in binary literals.
Insert digit separators in real literal Places digit separators to separate thousands in real literals of float/double/decimal type.
Insert generic method invocation type arguments Inserts inferred type arguments of generic method invocation/delegate creation from method group expression. Available when caret is exactly at the end of method name
Insert lambda expression signature Adds explicit type specifications for implicitly-typed lambda parameters.
Introduce variable from standalone expression Introduces variable from standalone statement
Invert '?:' operator condition Inverts condition and swaps branches of the '?:' conditional expression.
Invert 'if' statement Inverts guard condition of an 'if' statement and swaps the branches' code accordingly.
Invoke extension method as static Changes invocation syntax from extension method to static method.
Iterate via 'foreach' Generates a 'foreach' statement iterating the expression.
Join attributes into single section Rearranges attributes into single section
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 null check with assignment Replace 'if' statement with code using ?? operator and throw expression
Join string literals Concatenates two string literals into one.
Make method partial Converts private void method to partial method definition.
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 into null-propagating expression Merge sequential null/type checks using the conditional access expression ('?.' 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 type to another file to match its name Moves current type to another file so that its name matches the name of the type.
Move variable declaration to outer scope Moves variable declaration to outer scope.
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 expression Replaces format method invocation with passing string interpolation expression. Use carefully, since some of format methods (like in logging frameworks) do not always execute the formatting of arguments while string interpolation expression always evaluates.
Pass 'string.Format' method invocation Replaces format method invocation with passing 'string.Format' method call result. Use carefully, since some of format methods (like in logging frameworks) do not always execute the formatting of arguments while 'string.Format' always produces string.
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 variable 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 imported 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 digit separators from numeric literal Removes digit separators from integer or real literals
Remove redundant parenthesis Removes parenthesis in case they are redundant
Remove string formatting method argument Removes format string item and corresponding formatting method argument from format method invocation. For more information, see code analysis and helpers for string literals.
Replace '.IfNotNull(x => x.Smth)'-like call with '?.' expression Replace usage of extension methods like '.IfNotNull(x => x.Smth)' with condtional access expression ('?.' operator)
Replace '?:' conditional operator with null-propagating expression Replaces use of conditional expression ('?:' operator) with null-coalescing (?? operator) or conditional access expression (?. operator)
Replace array initializer with 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 cast expression with safe 'as' cast Replace regular cast expression with safe cast 'as' expression.
Replace conditional access expression with unconditional access Replaces conditional access expression ('?.' operator) with regular unconditional access
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 null-propagation 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 conditional access expression ('?.' operator)
Replace null-propagating expression with '?:' conditional operator Replaces use of null-coalescing ('??' operator) or conditional access expression ('?.' operator) with conditional expression ('?:' operator)
Replace null-propagating expression with 'if' statement Replace C# 6.0 conditional access expression with 'if' statement
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 regular cast Replace safe 'as' cast expression with regular cast expression.
Replace 'var' with explicit type declaration Replace 'var' with explicit type declaration.
Reverse assignment statement Reverses source and destination parts of an assignment statement.
Reverse 'for' loop statement Reverses order of iteration in 'for' loop statement.
Specify array type explicitly Adds explicit type specification to array creation expression.
Specify enum member values Add explicit value specifications to all enum members
Split attributes into separate sections Rearranges attributes into separate sections
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 null-propagating expression into sequental checks Split conditional access expression ('?.' operator) into sequential null/type checks
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 string literal Splits string literal into two literals.
Split value return with '||' condition into 'if' and 'return' statements Works on an 'return' statement, which value is a disjunction ('||') of two simpler conditions. It converts the 'return' statement into 'if' and 'return' statements.
Split variable declaration into several ones Replaces variable declaration with several ones declared in inner blocks of the current block.
Surround string literal with 'string.Format' call Surrounds string lieral with 'string.Format()' method call.
Surround with "" Creates string literal of selection text.
To abstract/virtual/non-abstract/non-virtual member Makes type member abstract, virtual or non-abstract and non-virtual.
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' object Introduce field and precompile object of 'Regex' type For more information, see regular expressions assistance.
Uncomment Uncomments code block
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 instead of 'Add' method calls 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 instead of assignments 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' value Use 'System.Environment.NewLine' instead of "\n", "\r" or "\r\n" literal.
Use 'System.String.Empty' value 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: 4 July 2017