Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find orphaned methods in codebase

I'm sure we've all seen it before...A code base that has been around for a year or two, and as features have been added and bugs fixed, we end up with pieces of code that aren't actually in use anymore. I'm wondering if there is a way (especially in VS.NET with or without a third-party tool) to search the codebase and show me which methods are NEVER used anywhere else in the code?

The one challenge I can think of in regards to this type of utility would be the inability to map back when implicit type conversions are occuring. But assuming that wasn't a problem, what are my options?

like image 798
Brian G Swanson Avatar asked Aug 18 '08 18:08

Brian G Swanson


3 Answers

FxCop will warn you of methods where nothing calls them.

like image 176
Keith Avatar answered Oct 29 '22 01:10

Keith


As it turns out, one of the things that FxCop does is identify unused bits of code, but it sometimes misses stuff. However, your best bet would likely be ReSharper.

like image 4
rjzii Avatar answered Oct 29 '22 03:10

rjzii


Remember though that any public-facing method, property, or field can be accessed via reflection or in a derived type in a seperate assembly.

FxCop is the right answer here, but you also need to limit accessibility to your code. I.e. decorate things with private/protected/internal where appropriate.

like image 2
Chris Smith Avatar answered Oct 29 '22 03:10

Chris Smith