ReSharper 2020.2 Help

Generate Deconstructors

ReSharper | Edit | Generate Code | Deconstructors
Alt+Insert | Deconstructors

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

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

Generate a deconstructor

  1. In the editor, set the caret at 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 ReSharper | Edit | Generate Code… from the main menu. Alternatively, you can press Control+Shift+A, start typing the command name in the popup, and then choose it there.

  3. In the Generate popup, select Deconstructors.

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

    Generating the 'Deconstruct' method with ReSharper

  5. Click Finish to complete the wizard.
    You can also click Options to review or modify common code generation preferences on the Code Editing | Members Generation page of ReSharper options.

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

ReSharper: Generating the Deconstruct method with a quick-fix

This feature is supported in the following languages and technologies:

Language: C#Language: VB.NETLanguage: C++Language: HTMLLanguage: ASP.NETLanguage: RazorLanguage: JavaScriptLanguage: TypeScriptLanguage: CSSLanguage: XMLLanguage: XAMLLanguage: ResxLanguage: Build ScriptsLanguage: ProtobufLanguage: JSON
Feature is available in C#Feature is not available in Visual Basic .NETFeature is not available in C++Feature is not available in HTMLFeature is not available in ASP.NETFeature is not available in RazorFeature is not available in JavaScriptFeature is not available in TypeScriptFeature is not available in CSSFeature is not available in XMLFeature is not available in XAMLFeature is not available in Resource filesFeature is not available in build script filesFeature is not available in ProtobufFeature is not available in JSON
Last modified: 26 May 2020