Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

I think you want the DebuggerStepThrough attribute:

DebuggerStepThrough instructs the debugger to step through the code instead of stepping into the code.

[DebuggerStepThrough]
public void MyMethod()
{

}

This is especially useful for setters/getters since debugging into those usually just adds noise (example from msdn):

public int Quantity
{ 
    [DebuggerStepThrough] 
    get { return ComplexLogicConvertedToMethod(); } 
    [DebuggerStepThrough]      
    set { this.quantity = value ; }
}

Or to skip a specific section of the code:

... some production code
#if DEBUG
    Console.WriteLine("Debug version");
#endif
... some more production code
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top