CodeRush

DDC - Duplicate Detection and Consolidation

Duplicate code can be problematic in solutions because:

  • A bug could exist in each of the duplicate code blocks, making it harder to fix and increasing the chances that one of the bugs escapes correction and resurfaces on your customer’s machines after the corresponding bug is fixed;
  • Duplicate code is less flexible and harder to extend;
  • More code takes more time to read and understand, making it harder to bring new devs up to speed.

CodeRush finds duplicate code quickly (either in a low-priority background thread while you work, or in a high-priority foreground thread while you wait), and also lets you consolidate many forms of code duplication automatically.

The Duplicates Found icon - CodeRush by DevExpress icon at the bottom-right of the text editor indicates your solution contains two or more blocks of duplicate code that can be consolidated into a single block.

Duplicates Found hint - CodeRush by DevExpress

Click this icon to open the Duplicate Code tool window to see all duplicates found in the entire solution.

Duplicate Code window - CodeRush by DevExpress

You can consolidate found duplicates directly from the tool window. Right click the desired cluster and choose the target location for the consolidated code from the context menu.

Consolidate code from the Duplicate Code tool window - CodeRush by DevExpress

You can also start a search from the Duplicate Code tool window. Just click the Refresh icon in the upper left to refresh the results. The progress bar at the top of the window reports on search progress.

When the search is finished CodeRush immediately displays the results. The list on the left shows all found duplicates.

Click an entry in this list to see the corresponding duplicate code shown on the right side of the tool window.

The Duplicate Code tool window can be used to explore the connections between the detected duplicate code. CodeRush visually shows the connections between all corresponding identifiers in the found duplicate blocks. Each identifier has the same color as all corresponding identifiers in all code blocks.

Identifier highlighting - CodeRush by DevExpress

To navigate to a particular block of code (and consolidate starting with that block), just double-click the window showing the code block of interest.

Hover the mouse over the duplicate code issue bar appearing to the left of the source code. This will bring up the Duplicate Code Issue window:

Duplicate Code Issue window - CodeRush by DevExpress

From this window, you can navigate among duplicates using the left and right duplicate code navigation buttons. You can also bring up the Duplicate Code tool window using the Duplicates Found sign - CodeRush by DevExpress button in the middle. Code consolidation can also be invoked, if available, by clicking the desired consolidation location. Duplicate code can be consolidated into the current class, an existing helper class, a new helper class, or a new ancestor class. The locations available depend upon the location of the duplicate code. You can either choose the target position from the duplicate code issue hint or via the Code Consolidation wizard. Choose "to another position" from the duplicate code issue hint to call the wizard.

Code Consolidation Wizard - CodeRush by DevExpress

You can also call the Duplicate Code Issue window hovering the mouse over the duplicate code issue bar appearing to the right of the source code.

Duplicate Code Issue window - CodeRush by DevExpress

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.