[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Collapse]CodeRush
  System Requirements
  Improve Performance
 [Expand]Features by Language
 [Expand]Getting Started
 [Expand]How To
 [Expand]Coding Assistance
 [Expand]Navigation and Search Tools
 [Expand]Static Code Analysis
 [Expand]Visualization Tools
 [Collapse]Code Style Assistance
  [Expand]Code Formatters
   Programming Style Rules
   Naming Conventions
  [Collapse]Code Cleanup
    Code Cleanup Rules
   Remove Unused Assembly References
  [Expand]Document Formatting (C#)
   Document Formatting (XAML)
   Member Organization
   Move Member to Region
  Building Assistance
  Debugging Assistance
 [Expand]Refactoring Assistance
 [Expand]Unit Testing Assistance
 [Expand]Decompiling Tools
 [Expand]Configuration Options
 [Expand]Extensibility
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Code Cleanup

Code Cleanup allows you to specify which Refactorings and Code Formatters CodeRush should apply to a document during cleanup. This feature helps you refactor a large amount of code.

Expanded Configure Cleanup

  • Open the Editor | C# (Visual Basic) | Code Cleanup options page.

  • Choose rules CodeRush should apply when you call code cleanup and enable "Apply In Action".

  • Choose rules CodeRush should apply in code cleanup before a file is saved and enable "Apply on Save".

Note

CodeRush does not clean up a file when you close the unsaved file or solution.

  • Enable the Apply Code Cleanup when saving a document option to allow CodeRush to clean up a file before it is saved.

  • Click OK to save and apply the settings.

Expanded Clean a File Up

Follow the steps below to execute code cleanup in an open file:

  • Place the caret anywhere in your code.
  • Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  • Choose Code Cleanup from the menu and press Enter.

The screencast below shows the code cleanup with applied Organize members and Format document rules.

You can also use the following methods to execute code cleanup:

  • Visual Studio menu

    Open the CodeRush | Edit menu and choose Cleanup Document.

  • Visual Studio toolbar

    Click the Run Code Cleanup button on the CodeRush Visualize toolbar.

Expanded Clean a File Up on Save

Click the Save button or press Ctrl + S in the editor.

The screencast below shows the code cleanup with applied Organize members and Format document rules.

Expanded Clean a Project Up

Follow the steps below to execute code cleanup in a project:

  • Right-click the project you want to clean in the Solution Explorer.
  • Select CodeRush Cleanup in the context menu.

CodeRush shows a progress window when the project is cleaned.

If you cancel the process, the code remains unchanged.

Note

Use Visual Studio's Undo action (Edit | Undo menu item) to undo the cleanup after its completion. This action is available when a document is open.

Expanded Clean a Folder Up

You can run Code Cleanup for a selected folder (folders) in the Solution Explorer.

Right-click the folder (folders) in which you want to clean files and select CodeRush Cleanup.

A progress window appears when CodeRush cleans files for a selected folder (folders).

If code cleanup is cancelled while it is still in progress, all code remains unchanged.

Expanded See Also

Is this topic helpful?​​​​​​​