开发者

VS2005: when stepping through C# code, is there way to skip through sections of code?

What can be done to skip through the parts of code when stepping through code? I find this particularly annoying when the debug开发者_StackOverflowger jumps to property gets and sets. Is there way to avoid this?


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.


there'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).


You could use "run to cursor" for one time breakpoints.


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.


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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜