避免在c#中为一段代码调试和调用堆栈(Avoid debug and callstack for a piece of code in c#)

在Delphi中,编译器指令{$ d-}和{$ l-}允许您有效地避免为已定义的代码段生成调试和局部变量信息。

在实际的问题中,它具有从调试视图中“隐藏”代码的效果,它不会出现在调用堆栈中,并且在调试时不会进入它。

有没有办法在使用VS 2008的c#中实现相同的结果?

注意:原因是我们有一个稳定的框架,不需要调试,但往往会搞乱调用堆栈和标准调试流程。

In Delphi the compiler directives {$d-} and {$l-} allow you to effectively avoid generation of debug and local variable information for a defined section of code.

In a practical matter that has the effect to "hide" the code from the debug view, it doesn't appear in the call stack and you don't step into it while debugging.

Is there any way to achieve the same result in c# using VS 2008?

Note: The reason is we have a stable framework which does not need to be debugged but tend to mess up with the call stack and with the standard debug flow.

最满意答案

我使用DebuggerNonUserCodeAttribute,因此默认情况下您不会中断或进入代码; 但是,对DebuggerStepThrough的好处是,您可以转到Options-> Debugger-> Just My Code设置,并允许打破/调试您标记的代码。 如果您遇到问题,这会有很大帮助。 我通常在整个课程上使用它。

顺便说一下,调用堆栈会自动隐藏用这个属性标记的非用户代码:)当然,您只需右键单击调用堆栈窗口并切换“显示外部代码”以隐藏/显示丢失的堆栈信息。

I use DebuggerNonUserCodeAttribute so that you by default do not break or step into the code; However, the benifit to this over DebuggerStepThrough is that you can go to the Options->Debugger->Just My Code setting and allow breaking/debugging of the code you marked. This helps significantly if you have issues. I typically use it on entire classes.

BTW, the call stack will automatically hide non-user code as marked with this attribute :) Of course you can simply right-click the call stack window and toggle "Show External Code" to hide/show the missing stack information.

更多推荐