ReSharper Web Help

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

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/property.

If there is a base type constructor with parameters, they are also declared as parameters of the generated constructor and passed to the base class constructor.

To generate a constructor
  1. Position the caret within a class where you'd like to generate a constructor.
  2. On the main menu, choose ReSharper | Edit | Generate Code, or press Alt+Insert.
  3. From the Generate pop-up menu, select Constructor.
  4. On the Generate constructors page of the Generate wizard, select type members that should be initialized in the new constructor. Optionally, select one or several base class constructors. For every selected base constructor, a new constructor will be generated that will call the base and additionally initialize selected members.
    Generate Constructors
  5. Optionally, use the following controls:
    • Access Rights defines common access rights for all constructors that the wizard generates.
    • Copy XML documentation copies XML documentation from all base constructors.
  6. Do one of the following:
    • To configure XML documentation options individually for specific constructors, click Advanced. After finishing this step, click Next.
    • Otherwise, click Finish to complete the wizard. For example, if a single base constructor and a single class member is selected, as shown above, ReSharper generates the following constructor:
      Generate Constructors

     Note

    Note that the name of generated constructor parameter classDeclaration differs from the name of property myClassDeclaration. This is accomplished by specifying my as the default prefix for instance fields in Languages | Common | Naming Style tab in the ReSharper Options dialog box. This forces ReSharper to drop the prefix when generating parameters based on instance fields. Were the prefix not specified, ReSharper would generate the parameter with the same name as the initialized field, and used this. qualifier in the initializing expression:
    this.myClassDeclaration = myClassDeclaration;

See Also

Procedures

Reference

External Links