删除未使用的code在Visual Studio [英] Removing unused code in Visual Studio

查看:188
本文介绍了删除未使用的code在Visual Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在与此相关的问题:删除未使用的引用,我想知道是否有从Visual Studio解决方案删除未使用的类,结构,委托等的工具。

In relation to this question: "Remove unused references (!= "using")", I would like to know if there is a tool for removing unused classes, structs, delegates, etc from a Visual Studio solution.

方案:

我有一个无组织的Visual Studio解决方案,包括1000年代:

I have an unorganised Visual Studio Solution which consists of 1000's of:

  • 本机方法进口
  • 结构
  • 代表
  • 枚举

而不是通过每个文件拖网单击查找所有引用,如果code正在某个地方使用的确定,就是那里,我可以简单轻松去除多余的code文件的机制?

Rather than trawling through each file clicking "Find All References" and determining if the code is being used somewhere, is there any mechanism by where I can simply remove redundant code files easily?

示例:

//This class contains a method called getRandomValue which returns type RANDOM
public class NativeMethods
{
    [DllImport("random.dll")]
    public static extern RANDOM getRandomValue();
}

//This is the RANDOM object as referenced by getRandomValue();
[StructLayout(LayoutKind.Sequential)]
public struct RANDOM
{
    uint a;
    uint b;
    uint c;
}

//This is redundant since nothing is referencing it.
[StructLayout(LayoutKind.Sequential)]
public struct MESSAGE
{
    IntPtr sender;
    IntPtr recipient;
    char[] mText;
}

注意自我:

我的直觉是,这将是因为不同的Java棘手,对象名不必是相同的文件名,和多个对象声明可以驻留在一个文件中,但是在这种情况下(我的情况)每一个对象在它自己的文件(具有相同名称)声明的。

My gut feeling is that this is going to be tricky since unlike Java, object names do not have to be identical to the file name, and multiple object declarations can reside within a single file, however in this instance (my scenario) every object is declared within its own file (with an identical name).

推荐答案

ReSharper的是清理你的code的最佳选择。

ReSharper is the best choice to clean up your code.

您可以免费使用它得益于 ReSharper的早期使用计划

You can use it for free thanks to ReSharper Early Access Program.

这篇关于删除未使用的code在Visual Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆