ReSharper 2017.2 Help

Generating Code with Code 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 method name to ger the suggestion to override it in the current type:

Coding Assistance Code Completion Generative generative completion 01
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 to create a read-only or a read-write property with the corresponding name according to your naming style:

Coding Assistance Code Completion Generative generative completion 04

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 properties
  • ctorfp - a constructor that initializes all fields and properties

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

Coding Assistance Code Completion Generative generative completion 05

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

Templates in completion lists

All your live templates and postfix 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 .

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

Reference Options Templates Live Templates Predefined CSharp Other psvm before

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

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

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 Feature is available Feature is available Feature is not available Feature is not available Feature is not available Feature is not available Feature is available Feature is not available Feature is not available Feature is not available Feature is not available Feature is not available Feature is not available Feature is not available

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

Last modified: 11 December 2017

See Also