Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean up unwanted code C#

I got a C# application with Visual Studio 2005. The code has some 300 KLOC, which has been abused over 3 years.

When I was going through code found out that lot of unused functions/methods/properties. Its not possible to clean the code manually (Requires checking each member and if found no references delete it.)

I am looking to automate this process, by VS macro, which will walk through each member in code, if it does not have any references it should delete it, if found any references, check its calling member's references if calling member, does not have any reference it should delete both and so on.

I am sure some one would have cracked it earlier.

like image 869
NileshChauhan Avatar asked Mar 05 '09 09:03

NileshChauhan


3 Answers

Resharper has a Clean Code function and gives pretty good indication of which methods/classes aren't being used.

like image 173
Ruben Steins Avatar answered Nov 03 '22 00:11

Ruben Steins


You can query your code base with NDepend using CQL to find out which methods and classes are not being used.

like image 27
idursun Avatar answered Nov 02 '22 22:11

idursun


Be careful of code that is invoked via reflection. A lot of refactoring tools will flag this code as not being accessed when in fact they are.

The safest is to run your unit tests (you do have these already right?) before and after the refactoring to ensure that everything still works.

like image 25
rein Avatar answered Nov 02 '22 23:11

rein