JetBrains Rider 2018.2 Help

Generating Deconstructors

Code | Generate | Deconstructors
Alt+Insert | Deconstructors

JetBrains Rider helps you quickly generate overloads for the Deconstruct method with selected members.

Before generation

After generation

public class Version { public int Major { get; } public int Minor { get; } }

public class Version { public int Major { get; } public int Minor { get; } public void Deconstruct(out int major, out int minor) { major = this.Major; minor = this.Minor; } }

To generate a deconstructor

  1. In the editor, set the caret on the type name or within a type at the line where you want to insert a deconstructor. If the caret is on the type name, the generated code will be added in the beginning of the type declaration.

  2. Press Alt+Insert or choose Code | Generate... from the main menu. Alternatively, you can press Ctrl+Shift+A, start typing the command name in the pop-up, and then choose it there.

  3. In the Generate pop-up menu, select Deconstructors.

  4. In the Generate dialog that appears, select type members that should be used in the deconstructor.

    Generating the 'Deconstruct' method with JetBrains Rider

  5. Click OK to complete the wizard.

JetBrains Rider also checks if a type contains the required deconstructor, and if not, suggests a quick-fix based on the tuple deconstruction.

JetBrains Rider: Generating the Deconstruct method with a quick-fix
Last modified: 21 December 2018

See Also