Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine Unused Methods and Properties

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?

like image 256
Brett Allen Avatar asked Dec 08 '22 04:12

Brett Allen


1 Answers

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.

like image 67
Rob Levine Avatar answered Jan 01 '23 23:01

Rob Levine