简体   繁体   English

VS2005:单步执行C#代码时,是否可以跳过代码部分?

[英]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.

相关问题 C#vs2005 .net 2.0:代码优化 - c# vs2005 .net 2.0: code optimization C# 仅在单步执行代码时出现调试错误 - C# Debugging Error Only When Stepping Through Code VS2005 C#:是否有一种特殊的visual-studio方法来创建属性,还是可以只键入代码? - VS2005 C#: is there a special visual-studio way to create properties or can the the code just be typed out? ODAC&C#-TNS:发生连接超时-仅通过VS2005调试器进行连接 - ODAC & C# - TNS: Connect timeout occurred - Connecting only through VS2005 debugger C#:为什么VS2005中的一个代码编辑器选项卡上有星号? - C#: why is there an asterisk on one of the code editor tabs in VS2005? VS2005,C# - 数据绑定组合框 - 默认情况下代码隐藏给我错误 - VS2005, C# - Databound combo boxes - code behind is giving me errors by default VS2005中的C#:this()会为继承的类执行基础构造函数代码吗? - C# in VS2005: will this() execute the base constructor code for an inherited class? 从未管理的项目(C / C ++ VS2005)调用托管代码(C#/ Visual Basic VS2010) - Calling managed code (C#/Visual Basic VS2010) from an unmanagened project (C/C++ VS2005) 在VS2005中更改ConnectionString(C#) - Change ConnectionString in VS2005 (C#) VS2005 C#:重新加载参考 - VS2005 C#: Reloading a reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM