Friday 17 February 2012

System.Diagnostics.DebuggerDisplay Attribute

When an object is viewed in the debugger, by default each value displayed is the result of the class, struct, property or fields's ToString() method. As an example, this object:
would be displayed like this in the Watch / Locals windows:



If you want to display more useful information, you can decorate the class, struct, property or field with the DebuggerDisplay attribute. The attribute's constructor takes a string parameter, which specifies the caption to display. The string can contain expressions to evaluate, if enclosed in curly braces; expressions can include properties of the object being displayed. This example shows the class display as a string containing the contents of the name property, and the IntArray display showing the size of the array.
The object with the attributes is displayed like this:

No comments:

Post a Comment