简体   繁体   中英

DebuggerStepThrough Attribute - How to also skip child Methods

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.
}

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() .

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM