It was just today that I’ve found out there is something like a conditional breakpoint in Rider. Out of curiosity, I checked if there is something similar in Visual Studio for Mac. It was pretty hidden but works the same. Let’s see where should you look.

Why is it useful? 🤔

Before we start, let’s quickly answer why this feature is useful. Imagine you are debugging code. Most of the time the code works but for one value it fails. You want to debug it and see what is happening there. The problem is, the method you are going to check is executed many times. Too many. So you put the breakpoint and every time it is hit you check the value of your property. If you are more clever then you write the code looking like this:

if(yourValue == "theValueThatFails)
{
}

You put the breakpoint inside if and when it is caught you just proceed with debugging. Then you forget to remove the code and your teammates don’t accept your PR. Boring. If you know your IDE then you can put a conditional breakpoint. Let’s take a look.

Visual Studio for Mac

Let’s assume I have search functionality in my app. It just queries the database and retrieves the matching items. Pretty simple. Unfortunately, somehow my code doesn’t work when user types DELETE * FROM USERS. What’s more something strange is happening with my database. I would like to know why.

Firstly, I need to put a breakpoint in the chosen line (128 in this case). In the next step, you need to right-click it, so the context menu open.

VS4Mac – Breakpoint context menu

Now, as you assume, you need to choose “Edit Breakpoint…”. Voilá, another window will open.

VS4Mac – Edit breakpoint window

In the “Edit breakpoint” view you can find several useful options but to our interest is the last entry. You just need to write you C# condition click apply and run the app normally. When you conditionisTrue, your breakpoint will be hit. No more adding dummy ifs!

Rider

In Rider, everything is more or sell similar to Visual Studio for Mac, but you don’t need to go that deep to edit condition.

Firstly, add breakpoint it proper place. Assuming, you did it, right-click on the breakpoint. Voilá!

Rider – breakpoint context menu

Write your condition, click Done and you are good to go.

Summary

Maybe it’s me who didn’t know about it. To me, this discovery was pretty mind-blowing. It simplified my life, made me more productive and made my life easier.

If you have similar tips that you feel are not known by others, please let us know in a comment or write me a message. I hope this one will boost your productivity and save some time debugging!

[mc4wp_form id=”497″]

Leave a Reply

Your email address will not be published. Required fields are marked *