【发布时间】:2012-09-29 05:48:53
【问题描述】:
关于这个问题:“Remove unused references (!= "using")”,我想知道是否有工具可以从 Visual Studio 解决方案中删除未使用的类、结构、委托等。
场景:
我有一个杂乱无章的 Visual Studio 解决方案,其中包含 1000 个:
- 本机方法导入
- 结构
- 代表
- 枚举
不是通过单击“查找所有引用”来浏览每个文件并确定代码是否在某处使用,是否有任何机制可以让我轻松删除冗余代码文件?
示例:
//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 不同,对象名称不必与文件名相同,并且多个对象声明可以驻留在单个文件中,但是在这种情况下(我的场景)每个对象都在其自己的文件中声明(具有相同的名称)。
【问题讨论】:
-
可以考虑使用 ReSharper。它为代码清理提供了很好的支持。
标签: c# .net visual-studio-2010 visual-studio code-cleanup