Avoid debugging and callstack for parts of code in C #

In Delphi, the compiler directives {$ d-} and {$ l-} can effectively avoid generating debugging information and a local variable for a particular section of code.

In a practical question that has the effect of "hiding" the code from the debug view, it does not appear on the call stack, and you do not enter it during debugging.

Is there a way to achieve the same result in C # using VS 2008?

Note. The reason is that we have a stable structure that does not need to be debugged, but, as a rule, ruin the call stack and the standard debug stream.

+4
source share
3 answers

I use DebuggerNonUserCodeAttribute so that you don't break or enter code by default; However, thanks for this over DebuggerStepThrough is that you can go to setting Options-> Debugger-> Just My Code and allow breaking / debugging of the code that you noted. This helps greatly if you have problems. I usually use it for all classes.

BTW, the call stack automatically hides the non-user code marked with this attribute :) Of course, you can just right-click the call stack window and switch "Show external code" to hide / show missing stack information.

+6
source

I think you need the DebuggerStepThrough attribute:

DebuggerStepThrough tells the debugger to execute the code instead of entering the code.

 [DebuggerStepThrough] public void MyMethod() { } 

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

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

Or skip a specific section of code:

 ... some production code #if DEBUG Console.WriteLine("Debug version"); #endif ... some more production code 
0
source

Source: https://habr.com/ru/post/1335864/


All Articles