Skip to main content

Code Formatters

  • 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 + ~.

    ActionsMenu

    CodeRush adds the following items to Visual Studio’s light bulb menu (Code Actions Menu):

    • Code Formatters - perform routine changes in your code without code behavior change. For example, Collapse Accessors.
    • Refactorings — simplify code, improve readability, make code more flexible (for future changes), or bring the code to meet certain standard without code behavior change. For example, Inline Method.
    • Code Providers — can change code behavior or declare undeclared types and members. Use them to supplement your code with blocks which you might want to type manually. For example, Create Event Trigger.
  2. Choose the action from the invoked menu. For example, Collapse Getter.

    You can see a preview of the changes CodeRush can apply to your code. Code_Generation_Main

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

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 Formatters C# VB Razor XAML
Add/Remove Block Delimiters CRR_IconPassed CRR_IconPassed
Break Apart Parameters/Arguments CRR_IconPassed CRR_IconPassed
Break Apart/Line Up Attributes CRR_IconPassed
Collapse Accessors CRR_IconPassed CRR_IconPassed
Collapse/Expand Getter/Setter CRR_IconPassed CRR_IconPassed
Collapse/Expand Local Function CRR_IconPassed CRR_IconPassed
Collapse/Expand Method CRR_IconPassed CRR_IconPassed
Collapse/Expand Property CRR_IconPassed CRR_IconPassed
Expand Lambda Function CRR_IconPassed
Line Up Parameters/Arguments CRR_IconPassed CRR_IconPassed CRR_IconPassed
Remove All Redundant Block Delimiters CRR_IconPassed CRR_IconPassed
Sort Namespace References CRR_IconPassed CRR_IconPassed

Blazor Support

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

ActionsMenu

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