7.11.08

Displaying data in Visual Studio debugger variable windows

How can you display details of a custom type in debugger windows without expanding type tree?

Let’s consider following sample:

private static void Main()
{
var Js = new[]{
new IDableText("John"),
new IDableText("Jack"),
new IDableText("Joe"),
new IDableText("Jackson")
};

foreach (var j in Js)
{
// ...
}
}

class IDableText
{
public IDableText(string name)
{
this.Text = name;
this.CreationTime = DateTime.Now;
this.Id = Guid.NewGuid();
}

public DateTime CreationTime { get; private set; }
public string Text { get; private set; }
public Guid Id { get; private set; }
}

This code will produce all too known debug variable window:

image


But, if you decorate class IDableText with a built-in attribute like this…

[DebuggerDisplay("Text={Text}  CreationTime={CreationTime}  Id={Id}")]


…you’ll get more readable result.
image
Nice!

smile_shades

1.11.08

Riding a PDC wave…

Following a PDC2008 week the fine bits revealed are emerging on the Internet. Here come the Microsoft Pre-release Software Visual Studio 2010 and .NET Framework 4.0 Community Technology Preview (CTP) on Microsoft Downloads.

Next week it’s WinHEC 2008 and time to get dirty with drivers, debugging, devices and Windows 7 inside and out!

smile_secret