Back to Devexpress

Collapse/Expand Getter/Setter

coderushforroslyn-115460-code-style-assistance-code-formatters-collapse-expand-getter-setter.md

latest1.5 KB
Original Source

Collapse/Expand Getter/Setter

  • Aug 03, 2020

Purpose

Collapses the accessor code into a single line and vice versa. Single-line accessors make your code more compact. On the other hand, they can decrease code readability.

Availability

Available when the caret is on a get or set statement inside the property declaration, provided that the accessor consists of a single statement.

Usage

  1. Place the caret on a get or set statement.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Collapse Getter / Collapse Setter from the menu ( Expand Getter / Expand Setter if you are expanding the accessor).

After execution, the Code Formatter removes the line breaks and converts the accessor to a single-line form or expands it to a multiple-line form.

csharp
public int A {
    get { return a; } 
    set { 
        a = value; 
    }
}

Note

This feature is available as a part of Code Cleanup.

See Also

Collapse Accessors

Collapse/Expand Property

Collapse/Expand Method

Add Getter/Setter