ReSharper 2017.2 Help

Typing Assistance

In addition to saving your time by providing smart suggestions in completion lists, ReSharper provides other typing assistance features, which let you create and edit your code even faster.

Auto-Inserting Matching Delimiters

By default, whenever you type an opening delimiter (, [, ", or ', a paired character is inserted automatically (whenever appropriate). If you change your mind and press Backspace to delete an opening delimiter, its closing pair is also deleted. If the pairing closing delimiter already exists, ReSharper will not add another one. The matching symbols are inserted according to your formatting preferences.

Regarding braces {}, ReSharper can provide a closing brace immediately on typing the opening one, or on pressing Enter.

If necessary, you can change the default behavior. To do so, go to the Environment | Editor | Editor Behavior page of ReSharper options and use the controls in the Braces and Parentheses section.

Correcting Length/Count mistyping

ReSharper prevents you from stumbling over mistyped Length/Count properties of arrays/collections. As soon as you erroneously start typing the Count property for a usage of an array, ReSharper will allow you to pick it from the completion list and replace with the Length property, which you probably meant to type.

Completing mistyped Count property for array

In a similar way, it will help you call the Count property on a collection usage when you start typing the Length property by mistake.

Completing mistyped Length property for collection

The correct property will be there as soon as you accept the completion suggestion:

void Foo(int[] array, List<int> collection) { if(array.Length == collection.Count }

Generating equality and flag checks for enumeration types

When you need to compare a value of enum type to one of the members of this enum, just type a dot and then pick the desired enum member in the completion list:

Completing enum members to produce equality/flag checks

ReSharper will generate the comparison for you:

public enum Direction { North, East, South, West } void Turn(Direction whereTo) { if(whereTo == Direction.South }

Creating type parameter from usage in method parameters

When creating generic methods, you can easily add type parameters by typing T for a new parameter and choosing the corresponding item in the completion list

Creating type parameter from usage in method parameters

ReSharper will add a new type parameter to the method declaration and bring you to a position where you can type the name of the type parameter in both its declaration and usage:

Creating type parameter from usage in method parameters

After you finish typing the name, press Enter or Tab to go on typing.

Smart behaviour of dot and semicolon

By default, when you choose a method in the completion list ReSharper automatically adds parentheses and sets your caret between them in the position to start typing arguments. If you want to call the method without parameters, and chain-call another method, you can type the dot right where your caret is and ReSharper will move it to the right place:
myStringBuilder.AppendLine(./*caret*/) becomes myStringBuilder.AppendLine()./*caret*/
If you just typed a complete method call, and then decide to chain-call another method, you do not have to move your caret, just type the dot right after the final semicolon:
myStringBuilder.AppendLine();./*caret*/ becomes myStringBuilder.AppendLine()./*caret*/;

When you caret is inside parentheses, you do not have to move it outside to type the final semicolon, just type it right away or after the last argument:
myStringBuilder.AppendLine("line";/*caret*/) becomes myStringBuilder.AppendLine("line");/*caret*/

Correcting prefixes in verbatim string interpolation

Starting from C# 6.0, you can make the same string both interpolated and verbatim provided that you add the $ and @ prefixes in the correct order: $@"some string".

With ReSharper, the order will be always correct - a mistakenly typed @$ will be automatically replaced with the correct $@.

Adding NotNull/CanBeNull annotations

If code annotations support is enabled in your project, you can add [NotNull] and [CanBeNull] annotations, as well as generate null checks with a single keystroke:

  • When writing a method signature or member declaration, type ! or ? directly after the type name to get the item annotated with [NotNull] or [CanBeNull]:
  • If the symbol is already annotated with [NotNull] or [CanBeNull], you can type ? or ! correspondingly to change the existing annotation.
  • If a parameter is marked with the [NotNull] attribute, you can set the caret directly after the parameter name or parameter type and press !:
    private void Foo([NotNull] object/*!*/ arg/*!*/)
    ReSharper will generate a null check for this parameter. You can configure the null-check pattern on the Code Editing | C# | Null Checking page of ReSharper options.

By default, typing assist for [NotNull] or [CanBeNull] is enabled. If you want to disable it, clear the Annotate nullability... check-boxes on the Environment | Editor | Editor Behavior page of ReSharper options.

Converting expression-bodied to block-bodied members

When typing { after => in an expression-bodied member, ReSharper will convert it into a block body:

Last modified: 14 December 2017

See Also