Search code examples
c#visual-studiocode-cleanupduplicate-detection

Find duplicated code in overridden method


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?


Solution

  • 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.