ReSharper 2023.3 Help

Generative completion

One of the easiest way to generate code with ReSharper is to use code completion — all you need to do is to type several characters. Code generation suggestions are included in the lists of automatic completion and basic completion.

Here are a few examples of how you can generate code with code completion.

Overriding and implementing members

In the example below, code completion helps create an override for a virtual member from a base class. Start typing the base method name in a derived type, and you will get a suggestion to override it:

ReSharper: Completion suggestion for method override

After you accept the suggestion, the method body with the default implementation expands in the editor:

public class Derived : BaseClass { protected override void DoSomething(int x, string s) { base.DoSomething(x, s); } }

Properties for fields

To generate properties for a field, start typing the name of the field. ReSharper will suggest creating a read-only or a read-write property with the corresponding name according to your naming style:

ReSharper: Completion suggestion to generate a property for a field

After you accept the suggestion, the property body expands in the editor:

public class Properties { private int _myField; public int MyField { get { return _myField; } set { _myField = value; } } }

Type constructors

Depending on the existing members of the current type, ReSharper suggests different constructors in the completion list. To create a constructor, type ctor. In the completion list, you may see the following suggestions:

  • ctor — a constructor without parameters

  • ctorf — a constructor that initializes all fields

  • ctorp — a constructor that initializes all auto-properties

  • ctorfp — a constructor that initializes all fields and auto-properties

In the example below, all kinds of constructors are available.

ReSharper: IntelliSense for generating constructors.

If you accept the ctorfp suggestion, the constructor expands in the editor:

public class Person { private string age; public string Name { get; set; } public Person(string age, string name) { this.age = age; Name = name; } }

Generate 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 }

Templates in completion lists

All your live templates, postfix templates, and source templates appear in the completion list. Templates are identified by their shortcuts (here are the list of shortcuts of predefined templates). You can recognize them by the corresponding icon ThemedIcon.LiveTemplate.Screen.(Gray).png.

For example, to invoke the public static void Main template, type its shortcut psvm:

ReSharper: Code template in completion list

After you accept the suggestion, the Main method expands in the editor:

public static void Main(string[] args) { }

When you select items in completion lists using keyboard, the selection will jump to the first item after the last item and vice versa. You can disable this behavior by clearing Loop selection around ends of a list on the Environment | IntelliSense | Completion Appearance page of ReSharper options (Alt+R, O) .

This feature is supported in the following languages and technologies:

Language: C#

Language: VB.NET

Language: C++

Language: HTML

Language: ASP.NET

Language: Razor

Language: JavaScript

Language: TypeScript

Language: CSS

Language: XML

Language: XAML

Language: Resx

Language: Build Scripts

Language: Protobuf

Language: JSON

Feature is available in C#

Feature is available in Visual Basic

Feature is available in C++

Feature is not available in HTML

Feature is not available in ASP.NET

Feature is not available in Razor

Feature is not available in JavaScript

Feature is available in TypeScript

Feature is not available in CSS

Feature is not available in XML

Feature is not available in XAML

Feature is not available in Resource files

Feature is not available in build script files

Feature is not available in Protobuf

Feature is not available in JSON

The instructions and examples given here address the use of the feature in C#. For more information about other languages, refer to corresponding topics in the ReSharper by language section.

Last modified: 21 March 2024