October 16th, 2024

Improve your debugger game with editable expressions

Do you ever wish you could quickly test different queries on your collections or datasets while debugging? Do you want to save time and avoid writing code just to inspect your data? If you answered yes, then you will love the new editable expression feature in the Visual Studio debugger.

This feature allows you to modify the expressions textbox on the top of the IEnumerable visualizer dialog with your desired LINQ expressions. The visualizer updates in real-time, reflecting the data change resulting from your query. You can easily apply different filters or sort orders to your collections based on your needs.

In this blog post, we will show you how to use this powerful feature and how it can help you debug more efficiently and effectively.

Getting started

In a debugging session, launch the IEnumerable visualizer by hovering over a collection or dataset variable in the debugger and clicking on the magnifying glass icon. Alternatively, you can right-click on the variable and select View Visualizer from the context menu.

Image of highlighted View Visualizer option from the context menu.

This will open the IEnumerable visualizer dialog, where you will see the expressions textbox on the top. You can type any valid LINQ expression in this textbox and hit <ENTER> to apply it to your collection. The visualizer will update the data grid below with the result of your query.

Image of IEnumerable Visualizer, Expression box highlighted with nums2 in it

Use cases for editable expressions

The editable expression feature can be very useful for debugging dense datasets and complex collection manipulations. You can experiment with different data transformations and filters directly within the Visual Studio debugger, without having to write any code or switch to another tool.

For example, suppose you have a collection of products that you want to inspect. You can use the editable expression feature to filter out the products that are out of stock, sort them by price, and select only the name and price properties. Here is how you can do that:

Image of Visualizer formatting data

As you can see, the editable expression feature allows you to quickly and easily manipulate your data and see the results in the visualizer. You can also copy the expression from the textbox and paste it into your code if you want to use it in your application logic.

Give us your feedback

We hope you enjoy using the editable expression feature in the Visual Studio debugger. We would love to hear your feedback and suggestions on how we can improve it further. Please leave a comment below or use the Report a Problem tool in Visual Studio to let us know what you think.

We also want to thank you for your continuous feedback and support, which helps us make Visual Studio better for you. Stay tuned for more exciting features and updates coming soon!

Happy debugging!

Author