Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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"

This is built into Visual Studio 2010 Ultimate. I use it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top