如果在 Visual Studio 解决方案中使用 class 的 属性,我如何在 C# 中检查?

How can I check in C# if a property of class is used in a Visual Studio solution?

我有一个 C# class,其中包含各种用作键的静态 public 属性。

随着时间的推移,这个 class 被重构了很多次,一些键被弃用并且不再从同一 Visual Studio 解决方案中的项目的其他 classes 中引用。

我想通过反射或其他方式检查这些键(属性)中的任何一个是否在 Visual Studio 解决方案的其他 class 中使用。

我想编写一个单元测试来发现是否有任何键不再使用。

我怎么会做这种事?

如果您不使用反射访问您的 propery/class,您可以使用 Shift + F12 或右键单击property/class/field 并选择 'Find all references'。

这将打开 'Find symbol results' window,您可以在其中查看对代码元素的所有引用。