Customising Visual Studio debugger DataTips with DebuggerDisplay
The DebuggerDisplay attribute lets you change how an object is displayed in the Visual Studio debugger. Take these two simple classes representing a Company and an Employee.
public class Company
{
public string Name { get; set; }
public string StockSymbol { get; set; }
public IEnumerable<Employee> Employees { get; set; }
public Company(string name) { Name = name; }
}
public class Employee
{
public string Name { get; set; }
public Employee(string name) { Name = name; }
}
Create and initialise a new Company object with some data.
var company = new Company("Microsoft")
{
StockSymbol = "MSFT",
Employees = new List<Employee>
{
new Employee("Anders Hejlsberg"),
new Employee("Steve Ballmer"),
new Employee("Scott Guthrie")
}
};
Now, if you break into the code and start a debug session, you can hover over the company object to reveal its debugger DataTip. By expanding the nodes you can drill down into the object’s data.

The default information shown in the DataTip, although useful, can be improved by decorating classes with the DebuggerDisplay attribute. For companies, it might be useful to to display their Name and StockSymbol instead of the object type {Company}.
[DebuggerDisplay("{Name} - {StockSymbol}")]
public class Company
The same goes for the Employee object. We can show the employee name instead of the type {Employee}.
[DebuggerDisplay("{Name}")]
public class Employee
The result is a more useful and descriptive view of your Company objects.

For more info about customising Visual Studio’s debugger DataTips, see this article from MSDN Magazine: