Detecting duplicate code
Copy and paste development is generally regarded as a bad practice because bug fixes or enhancements in one area of code have to be repeated in all the other copies of the same code. Not only is this time consuming and tedious, but in large code bases, it's very easy to miss a change, leading to bugs and lower overall quality.
With Visual Studio, Microsoft has provided a way to detect duplicate code so that you can take remedial action to clean it up. Let's see how this is done.
Getting ready
You will need Visual Studio Premium or Ultimate for this recipe. Start it up and you're ready to go.
How to do it...
Create a new Class Library project under Visual C# and name it
OriginalLibrary
.Rename the
Class1.cs
file to theOriginalClass.cs
file and allow Visual Studio to rename the class itself when prompted.Add a second C#-based Class Library project to the solution giving it the name
DuplicateLibrary
.Rename the
Class1.cs
file to theDuplicateClass.cs
file, and as in step...