Some Background on why

Another thing that come out of last weeks training was Visual Studio Debuggers. This lead to me finding the coolest visualizer ever called TPL Dataflow Debugger Visualizer which allows you to easily visualize your TPL Dataflow

TPL DataFlow Debugger Visualizer

Because I found this awesome visualizer I decided that everything while debugging could be awesome if there were more of these so I have created a GitHub project called DotNet Pretty where I plan on creating many visualizers to really try light up the debugging experience.

What is DebuggerDisplayAttribute?

In case you don't know DebuggerDisplayAttribute is used when you want to have a "pretty" representation of the properties in your class when seeing it in the debugger.

What MSDN says

Debugger display attributes allow the developer of the type, who specifies and best understands the runtime behavior of that type, to also specify what that type will look like when it is displayed in a debugger.

How do you implement them

You simple place the DebuggerDisplay Attribute on a class like below


When the break point is hit instead of you seeing the objects ToString() implementation of the method as below


which of course you could override to show a nice message if you wanted to, you will get something like below


It doesn't seem like such a big deal with 1 object but think of how easy it would be to know stuff about objects when they in a list if they each implemented this attribute. Now obviously to use the attribute like this you need to own the object so you can add the attribute and release it.

DotNet Pretty's first contribution

The first contribution to DotNet Pretty is one that was used in the training which allows you to use the DebuggerDisplay Attribute in a different way.


This time you specify the target in the attribute like below


As you can see this is just floating in a random .cs file so it doesn't have to be placed anywhere specific in the code.

What it looks like

This time instead of seeing the ToString() method


You will see


Deploying Visualizers

Now obviously Visual Studio can't do magic to find out where the visualizers are across your whole machine so to get your custom visualizers to you work you simple need to drop the output assemblies in the path C:\Users\[username]\Documents\[Visual Studio Version]\Visualizers which in my case is C:\Users\GordonB\Documents\Visual Studio 2013\Visualizers.


How is the TDL Dataflow visualizer done?

In short the TPL Dataflow visualizer uses the DebuggerVisualizerAttribute which looks something like below


I will do a in detail post on DebuggerVisualizer Attribute when I add one to DotNet Pretty. For now though you can browse the source code of the TPL Dataflow Debugger Visualizer on CodePlex.

So what's the plan?

My plan at the moment is to find the .net types that I use most and implement visualizers for them. I'm planning on trying to get some nice ones in for TFS objects like Work Items. I'm hoping that others will use this library of visualizers and fork the code and help grow it.


Comment by James Curran

I love using DebuggerDisplay and debug visualized. Two things should be noted about them.

If it's a class that you have control over, you could just override the ToString() method. You should only need to use the DebuggerDisplay if you need the ToString to say something different than the debug message. And if the debug message is complex, it's best to define a special purpose property and reference that in the DebuggerDisplay attribute. This moves the complicity into compiled code and reduces the amount of parsing and reflection done at runtime.

internal class person
public string FirstName {get; set;}
public string LastName {get; set;}
public int Age {get; set;}

private string DebuggerString
get { return String.Format("{0} {1} is {2} years old",
FirstName, LastName, Age);

(The "nq" means "no quote", so the string is displayed without quotes around it.

Comment by James Curran

Ooops.. forgot to add that the "
[DebuggerBrowsable(DebuggerBrowsableState.Never]" means that property isn't shown among the properties of the object in the debugger --- it'll only be shown at the root.

Comment by cisshanu

Professionals for hiring with pure dedication involves talent, hard work, teamwork, continuous learning, full-time support for cost-effective product and quality control and you can easily get all these qualities in our programmers at very cheap rates.

Comment by Dot Net Training in Chennai

Your posts is really helpful for me. Thanks for your wonderful post.It is really very helpful for us and I have gathered some important information from this blog.If anyone wants to get Dot Net Training in Chennai reach FITA IT training and placement academy. http://www.dotnettrainingchennai.net/

Comment by technotips

Very nice blog ...........
<a href="http://technotips.co.in/live-project-training.htm">Best dot net training</a>