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