ReSharper
 
Get ReSharper
You are viewing the documentation for an earlier version of ReSharper.

Generate Type Constructors

Last modified: 21 July 2022

ReSharper | Edit | Generate Code | Constructor

Alt+Insert | Constructor (ReSharper_GenerateConstructor)

The constructor generation wizard creates a non-default constructor that takes parameters for selected fields , properties and auto-properties.

All generated constructors follow the same pattern where:

  • Each field , property, or auto-property included in the constructor is initialized with a parameter.

  • The name of the parameter is derived from the name of the corresponding field or property.

If there are non-default base type constructors, the required parameters are added to the generated constructor and passed to the base class constructor.

In the example below, this command is used to generate a new Circle constructor that takes two additional parameters to initialize _radius and _center fields.

This feature is supported in the following languages and technologies:

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.