Skip to main content

Code Cleanup and Member Organization

  • 2 minutes to read

Code Cleanup is useful when your solution contains much code that needs refactoring. It analyzes the code contained in the current file, project or entire solution, and applies certain refactorings where required.

Note

Current Code Formatting settings are also applied to code during cleanup.

CodeCleanup

To start the cleanup, click the Cleanup button in the DXCore Visualize toolbar or choose the appropriate item from the Solution Explorer context menu.

StartCodeCleanup

To specify the changes that Code Cleanup should apply to code, use the Rules options page. Below is a list of available changes.

C# rules:

  • Convert “” to string.Empty
  • Force braces in “do”, “while” statements
  • Force braces in a “fixed” statement
  • Force braces in “for”, “foreach” statements
  • Force braces in an “if..else” statement
  • Organize members
  • Force braces in “using”, “lock” statements
  • Make properties auto-implemented
  • Make the variable implicit
  • Remove all comments, excluding XML comments
  • Remove all regions
  • Remove the redundant “base” qualifier
  • Remove the redundant “this” qualifier
  • Remove unreachable code
  • Remove unused namespace references
  • Remove unused variables
  • Remove user blocks
  • Use an explicit internal modifier
  • Use an explicit private modifier

XAML rules:

  • Remove all comments
  • Remove default values

Note

The member organizer removes regions containing more than one member, regardless of the Remove All Regions rule availability.

Pay close attention to the Organize members item. This item has an additional options section that enables you to modify member organization rules as required. This section appears when you set focus to the Organize members checkbox on the Rules options page.

The member organizer groups code elements and sorts elements within groups. For example, the member organizer can create groups such as “Private fields”, “Internal fields”, “Public methods”, etc. The member organizer can also sort group items by name, parameter count, Generic parameter count, and return type name. CodeRush Classic locates code element groups in the same order as they are listed on the options page.

MemberOrganizer

Note

The member organizer does not process files containing preprocessor directives, with the exception of #region and #endregion.

Note

This product is designed for outdated versions of Visual Studio. Although Visual Studio 2015 is supported, consider using the CodeRush extension with Visual Studio 2015 or higher.