views:

1447

answers:

5

Is there a quick way to detect classes in my application that are never used? I have just taken over a project and I am trying to do some cleanup.

I do have ReSharper if that helps.

+2  A: 

I don't recommend deleting old code on a new-to-you project. That's really asking for trouble. In the best case, it might tidy things up for you, but isn't likely to help the compiler or your customer much. In all but the best case, something will break.

That said, I realize it doesn't really answer your question. For that, I point you to this related question:

http://stackoverflow.com/questions/71518/is-there-a-custom-fxcop-rule-that-will-detect-unused-public-methods

Michael Haren
A: 

It seems that this is one of the features proposed features for the next version of Resharper. That doesn't help yet, but hopefully the EAP is just around the corner.

Mike Two
A: 

Be careful with this - it is possible that you may remove things that are not needed in the immediate vicinity of the code you are working on but you run the risk of deleting interface members that other applications may rely on without your knowledge.

Andrew Hare
+2  A: 
  1. NDepend
  2. Resharper 4.5 (4.0 merely detects unused private members)
  3. Build your own code quality unit-tests with Mono.Cecil (some samples could be found in the Lokad.Quality the this open source project)
Rinat Abdullin
+1  A: 

Review the code carefully before you do this. Check for any uses of reflection, as classes can be loaded and methods can be dynamically invoked at runtime without knowing at compile time which ones they are.

RedFilter