简体   繁体   中英

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?

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.

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.

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.

视觉工作室中的潜在死亡方法,具有ndepend

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM