Back to Devexpress

How to: Convert Properties into the Expression-Bodied Structure

coderushforroslyn-403404-getting-started-examples-code-cleanup-how-to-convert-properties-into-the-expression-bodied-structure.md

latest2.1 KB
Original Source

How to: Convert Properties into the Expression-Bodied Structure

  • Apr 13, 2022
  • 2 minutes to read

CodeRush can adjust the existing code to the expression body style. For example, in the Convert to Property with Backing Field refactoring.

If you use this style in features that generate new members from scratch (for example, Declaration Providers, Declare Menu, and Code Template), the new code will automatically match the expression body style. The following screencast shows the applied expression body style to the Declare Method code provider:

This example shows how to define the expression body style for properties and apply this style in code cleanup.

Follow the steps below:

  1. Specify settings for expression bodies.

  2. Click Apply and OK to save these settings and close the programming style options page.

  3. Open the Editor | C# | Code Cleanup options page, select the “Apply expression body styles” rule, and enable the “Apply in Action” option for this rule.

  4. Click Apply and OK to save these settings and close the Code Cleanup options page.

  5. Copy the following code snippet and paste it to your project:

  6. Run code cleanup to apply the expression body style.

Note

You can also use the Use Expression Body refactoring to convert a property, method, constructor, destructor, getter or setter into the expression-bodied structure.