DebuggerDisplay Attribute
Team System June 3rd, 2009
The DebuggerDisplay attribute (System.Diagnostics.DebuggerDisplayAttribute) controls how a class or field is displayed in the debugger variable windows. When a custom object is displayed, the name of the class or the result of ToString() is shown. This can be changed with a DebuggerDisplay attribute.
Look at the following demonstration. I added the DebuggerDisplay attribute:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace DebuggerView { [DebuggerDisplay("User name={UserName} " + "& email={EmailAddress}")] class User { public string UserName { get; set; } public string EmailAddress { get; set; } } class Program { static void Main(string[] args) { User u = new User() { UserName = "maor", EmailAddress = "maor@example.com" }; } } }
The DebuggerDisplay attribute has a single argument, which is a string to be displayed in the value column for instances of the type. This string can contain braces ({ and }). Text within a pair of braces will be evaluated as a field, property or method.
And the result is:
Similar Posts:
- C# attributes
- C# Automatic Properties
- How to prevent SQL injections
- Create custom task for MSBuild – Step by Step
- How to: Expose Web Services to Client Script in AJAX
About


[...] Read full article Posted: Wednesday, June 03, 2009 10:56 PM by Maor David-Pur Filed under: Visual Studio, Tips [...]
Thanks for posting, I’ll definitely be subscribing to your blog.
The best information i have found exactly here. Keep going Thank you
Hi, gr8 post thanks for posting. Information is useful!
how long have you been writing this blog? I wish I found it earlier