DEV Community

Cover image for Show properties of an object during the debug
Emanuele Bartolesi
Emanuele Bartolesi

Posted on

4 1

Show properties of an object during the debug

During the debug sessions, very often, you have to check what is inside a property or in multiple properties.
It's very annoying every time to move the cursor on the object -> add to Quickwatch or try to click close to the arrow to see the values inside.

You can easily solve this problem with Visual Studio and improve your productivy during the debug.

The DebuggerDisplay attribute

For instance, you have this class with two properties inside.

    public class Person
    {
        public string Name { get; set; }

        public string Surname { get; set; }
    }
Enter fullscreen mode Exit fullscreen mode

You can tell to the debugger: "ehy, I want to see the values of these two properties".
You can simply add the DebuggerDisplay attribute on top of the class and you can format the string to display.

[DebuggerDisplay("Name = {Name} - Surname = {Surname}")]
Enter fullscreen mode Exit fullscreen mode

In the screenshot below, you can see the result.

Image description

If you want to go more deeper on the DebuggerDisplay attribute, this is the official documentation: https://docs.microsoft.com/en-us/visualstudio/debugger/using-the-debuggerdisplay-attribute?view=vs-2022

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay