I was watching The Machine Girl this weekend and It was awesome. It's about a girl out for revenge with a machine gun arm. I completely recommend it if you like campy gorefest asian movies. For those interested, there is a drill bra in the movie, haha (genius). But it got me thinking that I should probably write a post, so here it is.
There is always cool stuff inside of .NET and Visual Studio if you know what to look for. The other day I was reading some friends code, and I saw that he used a DebuggerDisplay attribute. It allows you to create a custom view of your objects in the Visual studio debugger. This attribute is very straight forward, but very powerful in the amount of time it can save you when debugging your application. I'll show you a cookie cutter example, but you can use your imagination as to how to use this particular attribute.
I first start by creating my class. I created a Person class.
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
public string CallMe()
{
return "Hello World!";
}
}
Wow, how terribly boring. When I debug my application it looks like this. I can't really see what's in my object without expanding the debugger view.

Now let me add the DebuggerDisplay attribute.
Awesome, right?!
The attribute looks like this.
[DebuggerDisplay("Person : {FirstName,nq} {LastName,nq}" +
" Address : {Street,nq} {City,nq} {State,nq} {ZipCode,nq}" +
" Call Method : {CallMe()}")]
All you have to do is place the properties you want to see between two curly braces. the ",nq" tells the debugger not to display quotes around the property I specify. You also have the ability to call any method inside of your class and display that return value. This is very power in scenaries where you have a list of your objects, you can see each object without guessing which index your really want to look at.
Adding this to your class might add a little noise to your code, but the value it adds when debugging greatly out weighs that. Hope you found this tip useful and hope it helps you bust those ghouls that lurk in your code. For more information check out the MSDN site for
DebuggerDisplay Atrribute.