views:

175

answers:

4

Hi,

I have legacy C# code and I am using Visual Studio 2008. I am looking for a tool, sort of code-analyzer that would say to me which class are not used and also some other useful information that might useful for code optimization.

If there is exact duplicate please specify.

Thank you.

+8  A: 

Have a look at NDepend.

Guillaume
+1  A: 

I recommend FxCop.

Simon Linder
Only if the classes are not public.
SLaks
I have not seen it in FxCop, which category is it?
Captain Comic
Which, knowing nothing else about the analyzed assembly, is correct behavior (ie, some other assembly could be referencing the classes in another solution). It'd be cool if there was a switch to toggle this, but the current behavior is correct for the purpose of FxCop.
gmagana
Right, only unused non-public methods are detected which is correct as gmagana stated. Uncalled private code produces CA1811: Avoid uncalled private code; category is Microsoft.Performance.
Simon Linder
CA1812 also flags unused internal classes
gmagana
+1  A: 

ReSharper (r#) has something of the sort.

Kindness,

Dan

Daniel Elliott
Great program but unfortunately not for free...
Simon Linder
Indeed but you do get what you pay for :-)
Daniel Elliott
Where is it in ReSharper? I have a project and I need to gather statistic of not referenced classes. That is somewhere is a class that is not referenced anywhere
Captain Comic
+1  A: 

The C# Test Coverage tool will tell you which code blocks (methods) are not executed during any single (or set) of runs. If you exercise your code thoroughly, blocks not executed are strong candidates for dead code.

Ira Baxter