The DebuggerDisplayAttribute in Visual Studio 2005 and IFormattable
I didn't realize this when I did my generic IFormattableObject implementation last week, but this week finds me writing a chapter on Debugging for an ASP.NET 2.0 book.
I was checking out the DebuggerDisplayAttribute and realized that it uses a similar format string style as my stuff. (Of course, my stuff isn't new, languages like Ruby and others have done it for years).
Anyway, the point was that I had been wondering if my idea "fit" into the world of .NET, but the syntax of this DebuggerDisplay attribute left me feeling more justified for my work. It's interesting though, that they are offering this attribute, when I always used ToString to do the same basic thing in the debugger. So, in a Whidbey world of DebuggerDisplayAttribute, what's ToString() for? I guess just Console.WriteLine(myObject)?
UPDATE: The "TracePoint" syntax in the VS 2005 Debugger is the same.
For example: {i.FirstName} Function: $FUNCTION, Thread: $TID $TNAME
prints out the variable i's property FirstName as well as some psuedo-variables like the current function, the Thread ID and Thread Name
Syntax
Description
[DebuggerDisplay(
"{_forename} {_surname}")]
Uses the private _forename and _surname members
[DebuggerDisplay(
"Employee- {ToString()}")]
The ToString method is called to provide the textual representation to be displayed as the value of the object
[DebuggerDisplay("Employee
( {Forename} {(_wizard) ?
\"Is a Wizard\" : \"Is
\"Is not a Wizard\" } )")]
An expression is evaluated in order to provide a differing representation to the user based on the value of a flag
Now playing: Kevin Lyttle - Turn Me On
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
If DebuggerDisplayAttribute emits nothing in the release build or only adds the information to the debugger information file (pdb), then there should be no problem. For example, if I loaded the release assembly in Reflector, I should not be able to find anything generated by the DebuggerDisplayAttribute in a release build.
- Joshua
Comments are closed.