Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 415
mcintyre321 Avatar asked May 10 '11 08:05

mcintyre321


People also ask

Can you set breakpoints in Vscode?

Breakpoints. Breakpoints can be toggled by clicking on the editor margin or using F9 on the current line. Finer breakpoint control (enable/disable/reapply) can be done in the Run and Debug view's BREAKPOINTS section. Breakpoints in the editor margin are normally shown as red filled circles.

How do I set a breakpoint in Visual Studio?

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

What is a breakpoint and why would you use a breakpoint in debugging your code?

A breakpoint helps to speed up the debugging process in a large program by allowing the execution to continue up to a desired point before debugging begins. This is more efficient than stepping through the code on a line-by-line basis.


2 Answers

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.

like image 111
Spongman Avatar answered Nov 15 '22 09:11

Spongman


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

like image 27
lukyer Avatar answered Nov 15 '22 10:11

lukyer