DebuggerStepThrough属性-如何也跳过子方法 [英] DebuggerStepThrough Attribute - How to also skip child Methods

查看:41
本文介绍了DebuggerStepThrough属性-如何也跳过子方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio调试器中工作时,我一直使用 System.Diagnostics.DebuggerStepThrough 属性跳过代码.
但是,有时候我希望它也跳过在我已应用 DebuggerStepThrough 属性的方法中调用的所有方法.

I've been using the System.Diagnostics.DebuggerStepThrough attribute to skip code when working in Visual Studio Debugger.
However, there are times when I want it to also skip any methods that are called from within the methods I've applied the DebuggerStepThrough attribute.

有没有办法做到这一点?
我不希望这会影响我已应用此属性的所有方法,但是有时我不希望调用/使用任何代码来为我已应用的方法中调用的所有方法打开调试器此属性.

Is there a way to do this?
I don't want this to affect all of the methods I've applied this attribute however there are times when I don't want any code that is called/used to open the debugger for all methods called within a method I've applied this attribute.

static void main(string[] args)
{
    Method1();
}

[DebuggerStepThrough()]
private static void Method1()
{
    Method2(); 'The Debugger is stopping in Method2 when I am manually stepping through the code
}

private static void Method2()
{
    '... Code I don't care about however debugger is stopping here.
}

所以上面的代码示例是我正在遇到的示例.
有没有办法让我告诉Visual Studio也逐步执行从 Method1()内部调用的方法?当前,当我在Visual Studio中手动浏览代码时,我发现必须向所有调用的方法添加 [DebuggerStepThrough()] 属性从应用了属性的方法中获取.在此示例中,调试器正在 Method2()中停止.

So the code sample above is an example of what I'm running into.
Is there a way for me to tell Visual Studio to also step over methods called from within Method1()?
Currently when I am manually stepping through code in Visual Studio I am finding that I am having to add the [DebuggerStepThrough()] attribute to all methods called even when they were called from within a method that had the attribute applied. In this example the debugger is stopping inside Method2().

我希望有一种方法可以让我不必将此属性应用于从 Parent 方法调用的所有方法.
也许这很容易让我迷失.

I'm hoping there is a way that would allow me to NOT have to apply this attribute to ALL of the methods called from the Parent method.
Perhaps there's just something easy I'm missing with this.

推荐答案

添加

Add a DebuggerStepperBoundaryAttribute to the method that you want to skip while stepping-through.

在示例代码中,当执行在 Method1() 调用处停止时,您逐步执行代码,而不是在 内部结束Method2 ,代码执行将继续执行 Console.WriteLine("Suddenly here") (当然,两个代码都在Method1中)和 Method2 运行):

In the sample code, when the execution stops at the Method1() call and you step through the code, instead of ending up inside Method2, the code execution will continue with Console.WriteLine("Suddenly here") (of course the code in both Method1 and Method2 is run):

static void main(string[] args)
{
    Method1();
    Console.WriteLine("Suddenly here");
}

[DebuggerStepThrough, DebuggerStepperBoundary]
private static void Method1()
{
    Method2();
}

private static void Method2()
{
    //Skipped
    Console.WriteLine("Skipped but still printing");
}

这篇关于DebuggerStepThrough属性-如何也跳过子方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆