What can be done to skip through the parts of code when stepping through code? I find this particularly annoying when the debugger jumps to property gets and sets. Is there way to avoid this?
views:
79answers:
7there's an option Step over properties and operators (Managed only)
or use F10 instead of F11 (with default keyboard binding)
Yes, there's a step over (F10) function, as well as a step into (F11).
When you used F10 the code simply steps over each statement unless you've set a break point in a deeper level. I've never found the debugger miss behave the way you've suggested , mind you I'm only using VS2008.
If you want to skip an entire method you can mark it with the DebuggerStepThrough
attribute:
[DebuggerStepThrough]
public void SomeMethod()
{
// lots of code...
}
public int SomeProperty
{
[DebuggerStepThrough]
get { return ComplexLogicConvertedToMethod(); }
[DebuggerStepThrough]
set { this.quantity = value ; }
}
Note that the attribute prevents the debugger from stepping into the method or property, but you can always place a breakpoint in that method and stop there1.
The attribute comes in handy especially when you have code like this:
DoSomething(obj.SomeProperty);
If you want to step into DoSomething
and press F11 you will - without the attribute - first step into SomeProperty
and then into DoSomething
. With the attribute however, you end up immediately in the DoSomething
method.
1If you want to completely prevent users from placing a breakpoint into a method you can use the DebuggerHiddenAttribute
.
You can set the attribute DebuggerStepThroughAttribute on any methods/properties you don't want to step into.
And you can also use the "Step Over" rather than "Step Into" command.
Add DebuggerStepThrough attribute to your property:
[DebuggerStepThrough]
private static void DO() {
Console.WriteLine("test");
}