

A simple tip to make your debugging sessions go easier - szcukg
http://codebetter.com/drusellers/2011/11/17/a-simple-tip-to-make-your-debugging-sessions-go-easier/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+CodeBetter+%28CodeBetter.Com%29&utm_content=Google+Reader

======
Sukotto
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...](http://blogs.msdn.com/b/jaredpar/archive/2011/03/18/debuggerdisplay-
attribute-best-practices.aspx)

(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.

------
CJefferson
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.

~~~
jf
You are correct sir.

~~~
szcukg
It's for the MS stack

------
Zev
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...](http://www.ultrasaurus.com/sarahblog/2011/11/debugging-objective-c-
in-xcode-for-ios/))

------
drusellers
Sorry guys, mostly .net peeps reading my blog. I cleared it up a bit in the
post.

