views:

167

answers:

3

I have a self-contained solution (non of the DLLs are used in any other project, so no worrying about Methods being used somewhere else).

I'm trying to figure out a way to determine every method/property that is not in use at all.

So I can't just look at private methods/properties, I need to also check Public methods and Properties.

I used a program in the past that did this, but only for Private Methods/Properties (things it guarantee weren't used by another project). Even if I could remember what it was, it did not meet my needs.

I've looked at nDepend, but not sure if this is something standard in the application, or if I will need to write a custom CQL statement for it.

Does anyone know of an application that does this, or if nDepend can do it, how hard it would be to do in nDepend?

+4  A: 

Resharper can give you this kind of information if you enable solution wide analysis.

SelflessCoder
That was what I used, Resharper, but it was before it had the new Solution Wide feature!Thanks for your help.
Aequitarum Custos
+1  A: 

Code Analysis (FxCop) can also locate unused methods and properties. It will generate warnings to the effect of "no upstream callers use this, consider removing it"

STW
And unlike Resharper, FxCop is FREE.
Kyralessa
+5  A: 

Yes - I'd say that NDepend is the tool of choice for this sort of dependency analysis.

It comes with loads of pre-canned CQL queries to do exactly this sort of thing, and it is very simple to write your own, based on the exisitng ones as templates.

At is simplest, a CQL query to detect unused methods can look like this:

SELECT 
  METHODS         // Get me a list of methods
WHERE 
  MethodCa == 0   // Where their afferent coupling is zero, (afferent coupling being the number of other methods that call it)

This is just a sample to show you how CQL looks. A more advanced query to find unused methods is supplied with NDepend.

See Patrick Smacchia's blog for more info.

Overall, other tools (FxCop and Resharper) can help with this too, but this sort of dependency analysis is NDepend's raison d'etre.

Rob Levine
Good information to have, will take a look at the demo for it. Only used Resharper before, but nDepend definitely looks useful, and good to know it comes with standard queries supplied with it!
Aequitarum Custos