1

Is there any program which can find duplicated code in a base method and overridden methods in inherited classes?

I have a base class for 20 classes that has about 30 virtual methods (I didn't write this code). I found one method that has almost the same code in all overrides. I think this same situation is occurring in other methods.

How can I find duplicated code blocks so that I can refactor it?

Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
Jacek
  • 11,661
  • 23
  • 69
  • 123

2 Answers2

3

Select the code in the visual studio editor. Right click-> Select Find matching clones in solution. Give it some time to process. It will tell you identical code in your solution.

Finding Duplicate Code by using Code Clone Detection . As noted in comments, this feature is available only in Ultimate and Premium versions of visual studio.

Resharper has something similar. Select the code, Right click-> Select Find similar code menu.

Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
1

Take a look at the Resharper DupFinder, perhaps? It's part of their command line tools.

http://blog.jetbrains.com/dotnet/2013/09/03/duplicate-finder-part-of-resharper-command-line-tools/

Nathan Taylor
  • 24,423
  • 19
  • 99
  • 156