关于这个问题:Remove unused references (!= "using"),我想知道是否有工具可以从Visual Studio解决方案中删除未使用的类、结构体、委托等。
场景:
我有一个未组织好的Visual Studio解决方案,其中包含数千个:
- 本地方法导入
- 结构体
- 委托
- 枚举
与其浏览每个文件,点击“查找所有引用”并确定代码是否在某处被使用,是否有任何机制可以轻松删除冗余的代码文件?
示例:
//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不同的是,对象名称不必与文件名相同,并且多个对象声明可以存在于单个文件中,但在此情况下(我的情况),每个对象都在其自己的文件中声明(具有相同的名称)。