📎 Webclip
C# attributes you should know #2: [DebuggerStepThrough] and [DebuggerHidden]
The post compares two C# debugging attributes. [DebuggerStepThrough] lets code execute without being debugged and can be applied to a class, struct, constructor, or method. [DebuggerHidden] also keeps code from being debugged, but it applies only to constructors, methods, and properties.
The main difference shown is in the Call Stack. Code marked with [DebuggerStepThrough] appears as external code, while code marked with [DebuggerHidden] does not appear there at all. The post also notes that with JMC enabled, breakpoints can still be hit even when [DebuggerStepThrough] is present.
Reading notes#
- [DebuggerStepThrough] executes code without debugging it, even if a breakpoint is set inside the block.
- It can be applied to a class, struct, constructor, or method.
- Breakpoints in code with this attribute are shown as non-hitable in debugging mode, except when JMC is enabled.
- [DebuggerHidden] is similar, but it can be applied only to a constructor, method, or property.
- [DebuggerStepThrough] still shows the code in the Call Stack as external code.
- [DebuggerHidden] removes the code from the Call Stack display entirely.
- The example uses a Car object and a DriveThroughMud() method to show the difference.
- The author prefers [DebuggerStepThrough] because it still provides Call Stack information and can be used on an entire class.
