Payson Welch
Payson Welch

Reputation: 1428

C# Debug Attribute

Is there an attribute I can specify on a method so that when I am debugging the debugger knows to step inside of a method? I am overriding a Databind() method and currently the debugger steps over it automatically.

Upvotes: 3

Views: 7244

Answers (4)

Payson Welch
Payson Welch

Reputation: 1428

Thanks for the answers guys, no one came up with what I was looking for though. I knew I had seen this before so I just did some more searching and found it again. There are several debugging attributes that live in System.Diagnostics, the ones I were looking for were DebuggerStepThrough() and DebuggerHidden().

    // Force the debugger to step through this code
    [DebuggerStepThrough()]
    public double GrandTotal
    {
        get
        {
            return (this.Subtotal + this.Tax + this.Shipping);
        }
    }

And...

    // Force the debugger to skip step through
    [DebuggerHidden()]
    public double GrandTotal
    {
        get
        {
            return (this.Subtotal + this.Tax + this.Shipping);
        }
    }

Edit: Oded you posted a comment about this above, this is actually what I was looking for :) I would have selected this as an answer but you did not post it as an answer?

Upvotes: 2

Scott Chamberlain
Scott Chamberlain

Reputation: 127563

I agree with Oded's answer but another option is use Debugger.Break(). This will cause your code to break every time it hits that line of code if the debugger is attached.

Upvotes: 1

jdcook72
jdcook72

Reputation: 370

What version of VS are you using? One thing that might be helpful, under Tools|Options, "Debugging node: Enable Just My Code (Managed only)" – clear, "Enable .NET Framework source Stepping" – set.

Do you have a breakpoint set in your override?

Upvotes: 0

Oded
Oded

Reputation: 499002

Just put a breakpoint inside the method you wish to debug.

If the breakpoint isn't hit when debugging, that would mean the method is not being called - are you sure you have overriden it correctly?

Upvotes: 4

Related Questions