Code Cleanup Rules
- 4 minutes to read
Code Style
| Title | Description | C# | VB[1] |
|---|---|---|---|
| Collapse property accessors | Converts all property accessors into a single-line form. | ![]() |
|
| Expand property accessors | Converts all property accessors into a multi-line form. | ![]() |
|
| Format document[2] | Runs the Document Formatting (C#) feature. | ![]() |
|
| Make properties auto-implemented | Converts properties with fully described accessors to auto-implemented properties. | ![]() |
![]() |
| Use ‘nameof’ | Converts string literals containing a variable or class member name to the nameof expression with the corresponding variable/member as an argument. | ![]() |
![]() |
Layout
| Title | Description | C# | VB[1] |
|---|---|---|---|
| Add copyright header | Adds a copyright comment at the file’s beginning. (configuration) | ![]() |
![]() |
| Move types to separate files | Moves all types or selected types from one file to new separate files. | ![]() |
![]() |
| Organize members | Sorts member declarations in the class and removes the redundant line breaks. | ![]() |
![]() |
| Sort namespace references | Sorts namespace references alphabetically or by length. | ![]() |
![]() |
| Sync Namespace with Folder Structure | Renames namespaces within a project, so they match the project’s folder structure. | ![]() |
![]() |
Programming Style
| Title | Description | C# | VB[1] |
|---|---|---|---|
| Apply the ‘Attribute lists’ style[2] | Combines attributes into a list or breaks attribute lists apart (according to the corresponding style rule). | ![]() |
![]() |
| Apply the ‘Attribute lists’ style to assembly-level attributes[2] | Combines assembly-level attributes into a list or breaks attribute lists apart (according to the corresponding style rule). | ![]() |
![]() |
| Apply the ‘Braces in statements’ style | Adds or removes optional block delimiters to/from all single-statement blocks (according to the corresponding style rule). | ![]() |
|
| Apply the built-in type style[2] | Converts explicitly-typed variable declarations to implicit or vice versa (according to the corresponding style rule). The related Code Action is Make Implicit/Explicit. | ![]() |
![]() |
| Apply the expression body styles | Converts single-statement properties and methods into expression-bodied structures. | ![]() |
|
| Apply namespace declaration style | Applies the namespace declaration preferences specified in the Visual Studio style option or the .editorconfig file. This setting defines the file-scoped or block-scoped namespace body styles for C# 10. | ![]() |
|
| Apply the ‘Optional parenthesis’ style to attributes[2] | Adds or removes optional parenthesis to/from the selected attributes (according to the corresponding style rule). | ![]() |
![]() |
| Apply the ‘Optional parenthesis’ style to the new object creation (for C#). Apply the ‘Optional parenthesis’ style to invocations (a constructor, method or property) (for Visual Basic).[2] | Adds or removes optional parenthesis to/from the new object creation (for C#) or invocations (for Visual Basic) according to the corresponding style rule. | ![]() |
![]() |
| Apply the ‘Optional parenthesis’ style to explicitly specify the order of operations[2] | Adds or removes optional parenthesis to explicitly specify the order of operations (according to the corresponding style rule). | ![]() |
![]() |
| Apply the ‘this’/‘Me’ qualifier style[2] | Adds ‘this’/ ‘Me’ qualifier where required or removes it where possible (according to the corresponding style rule). | ![]() |
![]() |
| Apply the variable declaration style | Converts CLR types to their keyword aliases or vice versa (according to the corresponding style rule). | ![]() |
![]() |
| Apply the visibility style[2] | Adds type/member visibility modifiers where required or removes them where possible (according to the corresponding style rule). | ![]() |
![]() |
| Remove redundant braces in blocks without parent statement[2] | Deletes optional block delimiters in “floating” code blocks. | ![]() |
|
| Sort modifiers[2] | Sorts type/member visibility modifiers according to the corresponding style rule. This | ![]() |
Redundant Code Removal
| Title | Description | C# | VB[1] |
|---|---|---|---|
| Remove all comments, excluding XML comments[2] | Cleans the code from the non-XML comments. | ![]() |
![]() |
| Remove all regions[2] | Cleans the code from the #region preprocessor directives. | ![]() |
![]() |
| Remove the redundant ‘base’/ ‘MyBase’ qualifier[2] | Deletes the ‘base’/ ‘MyBase’ qualifier in all member references where it can be omitted. | ![]() |
![]() |
| Remove the redundant type cast[2] | Deletes type casts in the places where they can be omitted. | ![]() |
![]() |
| Remove redundant type qualifiers[2] | Deletes type qualifiers in the places where they can be omitted and adds the required using/Imports statements. | ![]() |
![]() |
Strings
| Title | Description | C# | VB[1] |
|---|---|---|---|
| Convert to String Interpolation | Converts all formatted strings into the string interpolations. | ![]() |
![]() |
| Convert to string.Empty[2] | Converts all empty string literals (“”) into the string.Empty system constant. | ![]() |
![]() |
Unused Code Removal
| Title | Description | C# | VB[1] |
|---|---|---|---|
| Remove unused members | Deletes unused members. | ![]() |
![]() |
| Remove unused namespace references | Deletes the unused namespace references. | ![]() |
![]() |
| Remove unused parameters | Deletes unused method parameters. | ![]() |
![]() |
| Remove unused private types | Deletes unused private nested types. | ![]() |
![]() |
| Remove unused types | Deletes “internal”, “private” and “private protected” nested types, and “internal” regular types. | ![]() |
![]() |
| Remove unused variables | Deletes unused variables. | ![]() |
![]() |
| Replace unused variables with discard | Replaces unused variables with discard. | ![]() |
See Also
