[英]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 debugger jumps to property gets and sets. 当调试器跳转到属性get和set时,我觉得这特别烦人。 Is there way to avoid this? 有办法避免这种情况吗?
If you want to skip an entire method you can mark it with the DebuggerStepThrough
attribute: 如果要跳过整个方法,则可以使用DebuggerStepThrough
属性对其进行标记:
[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 there 1 . 请注意,该属性阻止调试器进入方法或属性,但是您始终可以在该方法中放置一个断点,然后在此处停止1 。
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
. 如果要进入DoSomething
,然后按F11键,将在没有属性的情况下首先进入SomeProperty
,然后进入DoSomething
。 With the attribute however, you end up immediately in the DoSomething
method. 但是,有了该属性,您将立即陷入DoSomething
方法中。
1 If you want to completely prevent users from placing a breakpoint into a method you can use the DebuggerHiddenAttribute
. 1 如果要完全阻止用户将断点放入方法中,则可以使用DebuggerHiddenAttribute
。
there's an option Step over properties and operators (Managed only)
可以选择“ Step over properties and operators (Managed only)
or use F10 instead of F11 (with default keyboard binding) 或使用F10而不是F11(具有默认键盘绑定)
是的,有一个跨步(F10)功能和一个跨步至(F11)。
您可以使用“运行至光标”设置一个断点。
When you used F10 the code simply steps over each statement unless you've set a break point in a deeper level. 使用F10时,除非您在更深的层次上设置了断点,否则代码仅会跳过每个语句。 I've never found the debugger miss behave the way you've suggested , mind you I'm only using VS2008. 我从来没有发现调试器小姐会像您建议的那样表现,请记住,我只使用VS2008。
You can set the attribute DebuggerStepThroughAttribute on any methods/properties you don't want to step into. 您可以在不需要的任何方法/属性上设置DebuggerStepThroughAttribute属性。
And you can also use the "Step Over" rather than "Step Into" command. 您也可以使用“ Step Over”而不是“ Step Into”命令。
Add DebuggerStepThrough attribute to your property: 将DebuggerStepThrough属性添加到您的属性:
[DebuggerStepThrough]
private static void DO() {
Console.WriteLine("test");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.