Collapse/Expand Getter/Setter

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.

    Note

    The blinking cursor shows the caret's position at which the Code Formatter is available.

    public int A {
        get {
            return a;
        }
        set {
            a = value;
        }
    }
    
  2. Use 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.

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

This feature is available as a part of Code Cleanup.

See Also