Reputation: 13467
Does Visual Studio 2013 have facility for showing unused functions?
What is the best solution to removing those functions?
Upvotes: 7
Views: 7766
Reputation: 13842
You can use the tool NDepend for hunting unused functions. NDepend is integrated in Visual Studio let's write code rule as C# LINQ queries. Around 200 default code rules are provided and 3 of them are about:
Such query can be executed and edited live in Visual Studio and matched methods (here unused methods) are listed.
Upvotes: 2
Reputation: 77334
If you enable Code Analysis (Project => Properties => Code Analysis), you will get a list of issues. Unused methods or variables are in this list as well as a lot of other potential issues.
Upvotes: 7
Reputation: 51390
ReSharper can detect and highlight dead code when solution-wide analysis is enabled.
It will report some false positives, so a manual review is still needed. For instance, R# won't detect when a function is used only through reflection, and will consider it's not used. The same goes for things like IoC containers based on conventions etc.
JetBrains provides some custom attributes to decorate your code with (like [UsedImplicitly]
). They guide the R# analysis engine and document your code.
Upvotes: 7