Custom Debugger Display Information in Visual Studio

Sometimes we would like to have some custom debugger information in the Visual Studio debugger. The Visual Studio custom debugger information tool can help us to do this.
 
Before looking at the debugger tool let's look at what debugger information looks like without using the custom debugger tool.
 
I have an Employee class as in the following:
  1. namespace ConsoleApplication1  
  2. {  
  3.     public class Employee  
  4.     {  
  5.         public string EmployeeName { getset; }  
  6.         public float Salary { getset; }  
  7.   
  8.         public Employee(float salary, string name)  
  9.         {  
  10.             Salary = salary;  
  11.             EmployeeName = name;  
  12.         }  
  13.     }  
  14. }  
Let's put a debugger on the main function and see what the debugger information looks like without using the custom debugger information.
 
 
If I put a debugger and point at the debugger display information, then it shows something like the preceding, the namespace classname and expanding the preceding will show the member value of that class.
 
Now let's modify the employee class to show the custom debugger information.
  1. namespace ConsoleApplication1  
  2. {  
  3.   
  4.     [DebuggerDisplay("Employee with name {EmployeeName} and Salary {Salary}")]   
  5.     public class Employee  
  6.     {  
  7.         [DebuggerDisplay("My Name is {EmployeeName}")]  
  8.         public string EmployeeName { getset; }  
  9.         [DebuggerDisplay("My salary is {Salary}")]  
  10.         public float Salary { getset; }  
  11.   
  12.           
  13.         public Employee(float salary, string name)  
  14.         {  
  15.             Salary = salary;  
  16.             EmployeeName = name;  
  17.         }  
  18.     }  
  19. }  
In the preceding class, I have added a DebuggerDisplay attribute to the class and the properties. The DebuggerDisplay attribute is available in the System.Diagnostic namespace.

The output will be as in the following:
 
 
So we can see that instead of showing the plain value of the properties in the debugger window we are able to set and see the customized values of the properties.