27

Is there a way to automatically find all unused public functions in a solution? I have resharper, and right now I have to do a "find usages" on each symbol, which is tedious--it seems like there should be a better way

dan
  • 9,712
  • 6
  • 49
  • 62
  • 1
    For passers-by: they may be unused by you at the present moment but if they are `public` then they are your API (just in case you've overlooked this). – CAD bloke Feb 02 '16 at 23:42
  • @CADbloke good point. In my case the `API` is private/internal (the consumers are just the devs on my team, I can see all the places it is used and can talk to all of the users). This is probably the only case that it's both safe and inexpensive to change an API like this. It becomes increasingly harder to safely make changes as the API becomes more widely used, especially if it published for use outside your company! – dan Mar 09 '16 at 15:23

1 Answers1

38

Of course there's a better way. Here's what you should do if you use ReSharper 4.5 or later:

  1. Go to ReSharper > Options > Code Inspection > Inspection Severity.
  2. Scroll down to "Unused symbols" category and set all containing items called "Non-private accessibility" to be shown - whether they're shown as hints, warnings, or suggestions is not relevant and is entirely up to you.
  3. In ReSharper > Options > Code Inspection > Settings, check "Analyze errors in whole solution". Press OK to apply changes in ReSharper Options.
  4. Right-click the solution node in Solution Explorer, and select "Find code issues". ReSharper will display various code issues that it detects in your solution in "Inspection results" tool window. Specifically, under "Unused symbols", you'll see all non-private types and members in your code that are not used.
Jura Gorohovsky
  • 9,886
  • 40
  • 46