Context Actions for C#
JetBrains Rider provides the following context actions for C#:
Name | Description |
---|---|
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 from the base candidate |
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 braces | Adds braces to statement |
Add deconstruct pattern component name | Adds explicit deconstruction pattern component name based on names in source pattern dispatch type. |
Add deconstruct pattern component name | Adds explicit deconstruction pattern component name based on names in source pattern dispatch type. |
Add explicit name of anonymous property | Adds explicit name specification to anonymous type property declaration. |
Add name to argument | Adds name to the 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 ordinary string literals as well |
Add TestCase attribute | Adds TestCase attribute to nUnit test method |
Add tuple component name | Adds explicit tuple component name based on names in target tuple type. |
Add variable designation for pattern | Introduce variable designation for type test/null-checking/relational pattern and possibly replace casts inside corresponding switch section |
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 Use Context Actions to add annotation attributes. |
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. |
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 |
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). |
Configure null-check assertion pattern | Opens ReSharper options page to configure null-check pattern. |
Configure parameter null-check pattern | Opens ReSharper options page to configure null-check pattern. |
Configure variable null-check pattern | Opens ReSharper options page to configure null-check pattern. |
Convert '?:' conditional expression to 'if' statement | Converts conditional expression whose value is returned or assigned to an 'if' statement. |
Convert '?:' conditional expression to switch expression | Converts conditional expression whose value is returned or assigned to a switch expression. |
Convert '==' operator to 'Equals()' call | Converts usage of equality operator ('==') to a call of '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 anonymous type to named class | Converts anonymous type to named class replacing its usages in selected scope. |
Convert auto-property to property with default body | Convert auto-property to property with default body For more information, see Use 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 compound assignment to regular assignment | Converts compound assignment to regular assignment |
Convert constructor to factory method | Converts constructor to factory method and updates usages to factory method call |
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' statement |
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 case guard clause | Works on 'if' statements at the beginning of switch section and splits it in a guarded section with the 'if' content and unguarded section with the else branch |
Convert 'if' statement to 'switch' expression | Works on 'if' statements that perform type checks or compare value of an expression with one or more constants. It converts 'if' statements into a single 'switch' expression. |
Convert 'if' statement to 'switch' statement | Works on 'if' statements that perform type checks or 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 null coalescing assignment to if statement | Converts null coalescing assignment to if statement |
Convert null coalescing expression to 'if' statement | Converts null coalescing expression to 'if' statement |
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 expression to conditional ?: expression(s) | Converts switch expression to a series of conditional (ternary) ?: expressions |
Convert switch expression to switch statement | Converts switch expression to switch statement. |
Convert 'switch' statement to 'if' statement | Converts 'switch' statements into one or multiple nested 'if' statements each checking for individual value. |
Convert switch statement to switch expression | Converts switch statement to switch expression. |
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 'using' declaration | Replace 'using' statement with 'using' declaration |
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. |
Converts member value check expression to recursive pattern | Replaces member read access to check for some constant value with corresponding pattern |
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 explicit property declaration for positional parameter | Create explicit property declaration for positional parameter of a record |
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 |
Deconstruct variable | Deconstructs single variable into multiple variables. |
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 lifting its closures if necessary. |
Fill object initializer | Initializes fields and properties in object initializer. |
Fix invalid escape sequences | Fix invalid escape sequences 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. |
Fix ternary expression in string interpolation | Wraps ternary expression in parentheses in order to prevent interpolated string from interpreting its false branch as format specifier |
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 relational expression | Flips the current relational expression e.g. x > 1 to x < 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 |
Generate type patterns | Generates type patterns |
Implement abstract member | Works on an interface member or an abstract member. Searches for classes where this member needs to be implemented and allows implementing 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 |
Include member access into object pattern | Replaces member access in source expression of 'is'/'switch' operators with corresponding pattern(s) |
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 control transfer statement | Inline control transfer statement like 'return' or 'continue' into the statement above |
Inline out variable declaration | Replaces local variable declaration as declaration expression |
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. |
Insert type specification after default literal | Converts default literal into default expression. |
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 'await foreach' | Generates an 'await foreach' statement iterating the expression. |
Iterate via 'foreach' | Generates a 'foreach' statement iterating the expression. |
Iterate via 'foreach' (based on Live Template) | 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. |
Mark string literal as string interpolation | Adds '$' to regular or verbatim string without changes to its content. |
Match file name with type name | Renames current file to match the name of the only top-level type declared therein. |
Merge deconstructed declaration | Merges deconstructed declaration into single variable declaration. |
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) |
Merge sequential pattern checks into complex pattern-matching | Merge sequential pattern checks into complex pattern-matching check |
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 local variable, constant or function declaration to outer scope | Moves local variable (with initialization), local constant or local function declaration 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 overridden and allows overriding 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 its usage(s) |
Push expression to variable initializer | Push equivalent variable usage expression(s) to its 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 Add and Remove #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. |
Remove tuple component name | Removes explicit tuple component name in tuple expression. |
Replace '.IfNotNull(x => x.Smth)'-like call with '?.' expression | Replace usage of extension methods like '.IfNotNull(x => x.Smth)' with conditional 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 Use Auto-Properties |
Replace cast expression with safe 'as' cast | Replace regular cast expression with safe cast 'as' expression. |
Replace casts with pattern variable | Converts 'if (a is B) {}' to 'if (a is B b) {}' and updates usages |
Replace conditional access expression with unconditional access | Replaces conditional access expression ('?.' operator) with regular unconditional access |
Replace explicit type specification with 'var' | Allows to replace type with 'var' even in the case when doing so would change the type of the variable. |
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 Use Auto-Properties |
Replace safe 'as' cast expression with regular cast | Replace safe 'as' cast expression with regular cast expression. |
Replace separate deconstruction declarations with single declaration | Replaces separate deconstruction declarations with single declaration |
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 guard clause with '||'-condition into two case labels with guard clauses | Works on a switch case label whose guard clause is a disjunction ('||') of two simpler conditions. It converts the switch case label into two separate labels. |
Split 'if' with '&&'-condition into nested 'if'-statements | Works on an 'if' statement, whose 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, whose 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 initialization | Moves variable initializer expression into separate assignment statement. |
Split local variable declaration and initialization | Moves variable declaration to outer scope. |
Split null-propagating expression into sequential checks | Split conditional access expression ('?.' operator) into sequential null/type checks |
Split recursive pattern into several consecutive checks | Extracts subpatterns of a pattern into checks joined by `&&` operator |
Split 'return' statement of boolean value to 'if' statement | Works on a 'return' statement, whose value is of the boolean type. It converts the 'return' statement into an 'if' statement with two 'return' statements, returning 'true' and 'false' values. |
Split 'return' with '&&'-condition into guarding 'if' and 'return' | Works on a 'return' statement, whose 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 a 'return' statement, whose 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 literal with 'string.Format()' method call. |
Surround with "" | Creates string literal of selection text. |
Test regular expression | Open dialog to edit and test regular expression against example 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 | Removes comments from a 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. For more information, see Code Inspection: Use object or collection initializer when possible. |
Use explicit discard declaration | Adds 'var' to discard declaration in order to prevent possible clash with other elements named '_' |
Use explicit or implicit tuple component name | Available on tuple components references |
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 implicit discard declaration | Removes redundant 'var' keyword from discard declaration |
Use object initializer instead of assignments | Replaces series of assignments with object initializer. |
Use separate declarations in deconstruction declaration/patterns | Replaces single declaration with separate variable declarations inside deconstruction |
Use Span<T> for stack allocated variable | Use Span<T> for stack allocated variable |
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. |
Last modified: 08 March 2021