Back to Devexpress

Code Formatters

coderushforroslyn-117246-code-style-assistance-code-formatters.md

latest5.0 KB
Original Source

Code Formatters

  • Oct 22, 2021
  • 2 minutes to read

Code Formatters improve code readability and layout to match a certain style without code behavior change. For example, Sort Namespace References.

The topics in the Code Formatters section describe each code formatter in detail. The description includes the purpose of the code formatter, its availability and the “how to use” example.

How to Use

  1. Invoke the Code Actions Menu. Place the caret in the part of the code you want to change, for example, on a get statement inside the property declaration, and press Ctrl + . or Ctrl + ~.

  2. Choose the action from the invoked menu. For example, Collapse Getter.

  3. Press Enter to convert the accessor to a single-line form.

csharp
class TestClass
{
    public int a;

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

The following table lists available code formatters and shows supported languages for them:

Code FormattersC#VBRazorXAML
Add/Remove Block Delimiters
Break Apart Parameters/Arguments
Break Apart/Line Up Attributes
Collapse Accessors
Collapse/Expand Getter/Setter
Collapse/Expand Local Function
Collapse/Expand Method
Collapse/Expand Property
Expand Lambda Function
Line Up Parameters/Arguments
Remove All Redundant Block Delimiters
Sort Namespace References

Blazor Support

You can apply code formatters from code sections in .razor files.

Note

The code formatters for Blazor are unable to update references in closed .razor files. Make sure all files that may be impacted by a particular code formatter are open in Visual Studio before applying it.

See Also

Document Formatting (C#)

Document Formatting (XAML)