DooDoo
DooDoo

Reputation: 13467

How to remove unused functions in Visual Studio 2013

Does Visual Studio 2013 have facility for showing unused functions?

What is the best solution to removing those functions?

Upvotes: 7

Views: 7766

Answers (3)

Patrick from NDepend team
Patrick from NDepend team

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.

Potentially dead method in visual studio with ndepend

Upvotes: 2

nvoigt
nvoigt

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

Lucas Trzesniewski
Lucas Trzesniewski

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

Related Questions