我可以将一个类标记为不是我的代码,以便调试器跳过它吗?
我有一个已经过彻底测试的实用程序类,并且我不希望 VS 调试器单步执行其任何方法。我想我听说过一种将某些内容标记为不是我的代码的方法,以便“仅我的代码”调试器设置导致调试器跳过这些方法调用,但我一生都不记得是什么了类属性是(我也无法成功谷歌找到它)。
我知道我可以将此类分离到其自己的程序集中并以发布模式构建它以缓解问题,但我想进入某些程序集(并且我想将此类保留在原来的位置)。
这可能吗,还是我想出这个选择?
更新
我使用两个选项(DebuggerStepThrough 和 DebuggerNonUserCode)进行了一些测试,我发现在启用/禁用 Just My Code
时,DebuggerNonUserCode 的行为与框架完全相同。 DebuggerStepThrough
属性始终会导致调试器跳过标有该属性的部分。为了保持一致性,我选择了 DebuggerNonUserCode。
I have a utility class that has been thoroughly tested, and I do not want the VS debugger to step into any of its methods. I think I have heard of a way to mark something as not my code so that the Just My Code
debugger setting causes the debugger to step over these method calls, but for the life of me I cannot recall what the class attribute is (nor can I successfully Google for it).
I know that I could separate this class into its own assembly and build it in release mode to alleviate the issue, but I would like to step into some of the assembly (and I would like to keep this class where it is).
Is this possible, or was I dreaming up this option?
Update
I did some testing with the two options (DebuggerStepThrough and DebuggerNonUserCode), and I found that DebuggerNonUserCode behaves exactly the same as the framework when having Just My Code
enabled / disabled. The DebuggerStepThrough
attribute always causes the debugger to skip the section marked with the attribute. For consistency's sake, I went with DebuggerNonUserCode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 DebuggerStepThrough 属性来跳过它。
You can use the DebuggerStepThrough attribute to skip over it.
您正在查找 DebuggerNonUserCode 属性。
You are looking for the DebuggerNonUserCode attribute.
如果通过名称来判断,
[DebuggerNonUserCode]
属性应该可以做到这一点,但事实并非如此。 (或者它在 VS2017 及更高版本中不起作用。)因此,接受的答案是错误的。从其名称来看,
[DebuggerStepThrough]
属性从未打算执行问题所要求的操作,并且毫不奇怪它不会执行该操作。 (或者它在 VS2017 及更高版本中不起作用。)因此,拥有 20 票赞成的答案也是错误的。起作用的
...是
[DebuggerHidden]
属性。 (learn.microsoft.com 上的文档)想想吧。
If one was to judge by its name, the
[DebuggerNonUserCode]
attribute should do it, but it does not. (Or it does not work in VS2017 and later.) So, the accepted answer is wrong.Judging by its name, the
[DebuggerStepThrough]
attribute was never intended to do what the question is asking for, and it comes as no surprise that it doesn't. (Or it does not work in VS2017 and later.) So, the answer with the 20 upvotes is also wrong.What does work
... is the
[DebuggerHidden]
attribute. (Documentation at learn.microsoft.com)Go figure.