枚举创建断点
我有一个枚举,我试图弄清楚什么代码实际上创建了它的实例。我有大量代码,并且我相当确定我正在寻找的代码位于许多晦涩的项目之一中,而这些项目不在我当前的解决方案中,因此查找用法不起作用。
我知道枚举上不存在构造函数这样的东西,但我真的希望有一种方法可以在任何代码创建和使用此枚举时中断执行并检查调用堆栈。我曾尝试在各个枚举值上放置断点,但它们永远不会切换,即使我知道它们正在被使用。
这是可能的吗,还是我需要采取不同的路线来找到我要找的东西。
I have an enum, and I am trying to figure out what code is actually creating an instance of it. I have a whole lot of code, and I am fairly certain the code that I am looking for is in one of the many obscure projects that is not in my current solution, so find usages won't work.
I know there is no such thing as a constructor on an enum, but I would really like a way to break execution and examine the call stack anytime any code creates and uses this enum. I have tried putting breakpoints on individual enum values, but they never toggle, even when I know they are being used.
Is this possible, or am I going to need to take a different route to find what I am looking for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,假设您控制枚举本身的代码,这在技术上是可行的:
另外,如果您真正想做的是在将此枚举的成员添加到特定集合时查看调用堆栈(正如您在评论中所说),为什么不在集合上查找用法(希望其范围较小?)并在添加项目的地方放置断点(或者更好的是,使用 $CALLSTACK psuedovariable 的 TracePoints)?
Well, it is technically possible, assuming you control the code of the enum itself:
Also, if what you really want to do is look at the callstacks when members of this enum are added to a particular collection (as you said in a comment), why not find usages on the collection (which hopefuly has a smaller scope?) and put breakpoints (or better yet, TracePoints with the $CALLSTACK psuedovariable) wherever items are added to it?
您可以使用
查找所有引用
,然后您可以在适当的位置设置断点。You can use
Find All References
, then you can set breakpoints in the appropriate places.您可以使用 VS 中的对象浏览器来搜索您的枚举。它包括引用的程序集(但不是作为项目的解决方案的一部分)。
You can use the Object Browser in VS to search for your enum. It includes assemblies that are referenced (but not part of your solution as projects).