Back to Devexpress

Use Expression Body

coderushforroslyn-115599-refactoring-assistance-use-expression-body.md

latest1.6 KB
Original Source

Use Expression Body

  • Aug 03, 2020

Purpose

Converts a property, method, constructor, destructor, getter or setter into the expression-bodied structure.

Availability

Available in the following cases.

  • When the cursor is on the name of a method, constructor, destructor, getter or setter in its declaration, assuming that it contains a single statement.
  • When the cursor is on the property name in its declaration, assuming that the property get accessor contatins a single return statement and the property has no set accessor.

Usage

  1. Place the caret on a method name.

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

  3. Select Use Expression Body from the menu.

After execution, the Refactoring converts the traditional method declaration to the expression-bodied structure.

csharp
double ConvertToUSD(Currency source, double amount) => amount / GetCurrencyRate(source);

Note

This feature is available as a part of Code Cleanup.

See Also

Collapse/Expand Method

Compress to/Expand Ternary Expression

Convert to/Decompose Initializer

ForEach to Linq