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; }
}
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}")]
In the screenshot below, you can see the result.
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
Top comments (0)