7 comments

[ 3.4 ms ] story [ 25.5 ms ] thread
I had no idea I could do this and can hardly wait to try it.

[edit: The author says it works for C#, F#, VB.NET, etc) in VisualStudio]

The related article goes into more depth including a list of DOs and DON'Ts: http://blogs.msdn.com/b/jaredpar/archive/2011/03/18/debugger...

(Quoting the above link)

Preferred Pattern

My personal preferred pattern for DebuggerDisplay attributes is to have the entire item be an expression: DebuggerDisplay. I then add a private instance property to my type named DebuggerDisplay and do all of my custom formatting in this property. Having the property be private is fine because nothing is private in the debugger.

  [DebuggerDisplay("{DebuggerDisplay,nq}")]
  public sealed class Student {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      private string DebuggerDisplay {
          get { return string.Format("Student: {0} {1}", FirstName, LastName); }
      }
  }
The ,nq suffix here just asks the expression evaluator to remove the quotes when displaying the final value (nq = no quotes).

I prefer this pattern because it’s only requires a single function to be evaluated, I can still have language specific expressions (which are nicely type checked by the compiler) and it doesn’t contribute to the public API of my type.

Amazingly, even after reading the article I'm still not sure what language this refers to. I think it's C#, when debugged in Visual Studio.
You are correct sir.
It's for the MS stack
I had the same problem. This leads to two situations:

1) The language looks java-derived, so I am probably /not/ interested. However, this would be a useful tip, and it might be useful with something I would use (jruby or clojure).

2) If it is specific to the MS stack, I have zero interest.

3) For all I know, this could apply (somehow) to the XCode ide in general, which would also be useful for me to know.

Always include information in the link that shows what sub-group of developers something pertains to.

Sorry guys, mostly .net peeps reading my blog. I cleared it up a bit in the post.
You can do something similar with iOS development as well, by implementing a -debugDescription method to return a NSString * object that is then printed out when you use print-object (or po) from GDB/LLDB.

If -debugDescription is not implemented, than the debugger will print out whatever -description returns, instead. -description is the same method that is called when an object is printed out with NSLog().

(more info: http://www.ultrasaurus.com/sarahblog/2011/11/debugging-objec...)