Back to Devexpress

Collapse/Expand Method

coderushforroslyn-115371-code-style-assistance-code-formatters-collapse-expand-method.md

latest1.2 KB
Original Source

Collapse/Expand Method

  • Aug 03, 2020

Purpose

Collapses a simple method body onto a single line and vice versa. Single-line methods make your code more compact, in other hand, they can decrease code readability.

Availability

Available when the caret is at the beginning of a method declaration or on the method name, provided that the method body consists of a single statement.

Usage

  1. Place the caret on the name of a suitable method.

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

  3. Select Collapse Method from the menu ( Expand Method if you are expanding the method).

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

csharp
public float USDtoEUR(float amount) { return amount / GetCurrencyRate(); }

See Also

Use Expression Body

Collapse/Expand Property

Collapse/Expand Getter/Setter