Is it possible to set a breakpoint in a method chain in VS, and if so how?
Asked Answered
P

3

5

Given the code

    [Test]
    public void Test1()
    {
        var a = new A();
        a
            .Method1()
            .Method2();
    }

is it possible to set a breakpoint so that execution pauses after Method1() has executed, but before Method2 without going to the definition of Method2 and putting a breakpoint there? When I do it, the breakpoint appears at the 'a'.

Parr answered 10/5, 2011 at 8:58 Comment(2)
Another good reason not to violate the Law of Demeter :-)Dragline
Another reason not to use fluent interfacesParr
P
0

No, the debugger's unit of executable code is a statement. There are only two in the method body in your snippet. Post feature requests to connect.microsoft.com. It's going to be a hard sell, it is not technically impossible but a potentially heavy re-engineering effort.

Polled answered 10/5, 2011 at 11:7 Comment(1)
You can actually step through to that stage using "f11 - step into", so it's probably not too hard for them to do.Parr
T
7

you can't set a breakpoint there, but you can set your breakpoint on the whole statement, and then use the "Step into Specific >" command on the right-click menu (Debug.StepIntoSpecific) to step into Method2().

you can also do repeated step in/step out to step through the indivdual method calls of the compound statement.

Twibill answered 11/5, 2011 at 23:5 Comment(1)
Thank you! Didn't know that hidden gem in Visual Studio but it can be really useful! (It has a strange German translation though… “Einzelschritt in Angabe”)Irritant
M
2

Use Rider instead of Visual Studio. IntelliJ Idea is capable of logical step in when fluent syntax is used. It is 2017 and fluent syntax is everywhere (LINQ). Shame on Visual Studio (even 2017).

Monometallic answered 20/2, 2017 at 11:42 Comment(0)
P
0

No, the debugger's unit of executable code is a statement. There are only two in the method body in your snippet. Post feature requests to connect.microsoft.com. It's going to be a hard sell, it is not technically impossible but a potentially heavy re-engineering effort.

Polled answered 10/5, 2011 at 11:7 Comment(1)
You can actually step through to that stage using "f11 - step into", so it's probably not too hard for them to do.Parr

© 2022 - 2024 — McMap. All rights reserved.