Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A Generic List and Dictionary Debugger Visualizer for VS.NET

0.00/5 (No votes)
27 Aug 2011 2  
A cool List and Dictionary debugger visualizer for VS.NET 2005, 2008 and 2010
ListVisualizer2008

Introduction

This is a simple List<T> and Dictionary<T,T> debugger visualizer for Visual Studio .NET 2005, 2008 and 2010. The only requirement for it to work is that the classes inside the lists or dictionaries should be marked as [Serializable].

Background

I used the nice article Create a Debugger Visualizer in 10 Lines of Code as a starting point. I recommend this article for further details on how to implement a custom debugger visualizer.

Using the Code

For installing the visualizer only, download the List Visualizer 2005, 2008 or 2010 according to the Visual Studio .NET version you would like to use. Run install_vs2005.cmd, install_vs2008.cmd or install_vs2010.cmd in a Visual Studio Command Prompt window. For Windows Vista, make sure to run the command prompt as Administrator.

Note that the Visual Studio path in the cmd files uses the default installation path, c:\Program Files\Microsoft Visual Studio 8 (for VS.NET 2005), c:\Program Files\Microsoft Visual Studio 9.0 (for VS.NET 2008) and c:\Program Files\Microsoft Visual Studio 10.0 (for VS.NET 2010). If you installed it in a different location, you might need to change the bat file and the post build events in the projects.

The default path for visualizers in 2005 is C:\Program Files\Microsoft Visual Studio 8\Common7\Packages\Debugger\Visualizers, in 2008 is c:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers and in 2010 is c:\Program Files\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\Visualizers. Just copy the assemblies there for a manual installation.

The source code contains both VS.NET 2005 (ListVisualizer.sln) and VS.NET 2008 solutions (ListVisualizer2008.sln). The post build event automatically deploys the visualizer for testing. Note that ListVisualizer2008.sln also contains the VS.NET 2005 projects that may be removed in case 2005 is not installed.

The source code for VS.NET 2010 can be found in a different zip file.

Points of Interest

I had to cast the generic types to non-generic interfaces to work with the variable that is being debugged:

// Get the list
IList list = (IList)objectProvider.GetObject();
 
// Get the dictionary
IDictionary dict = (IDictionary)objectProvider.GetObject();

After that, I used Reflection to retrieve object properties and fields to be displayed in the grid view:

// Retrieve the properties
PropertyInfo[] properties = singleObj.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
    dgvList.Columns.Add(property.Name, property.Name);
    columns.Add(property.Name, "P");
}
// Retrieve the fields
FieldInfo[] fields = singleObj.GetType().GetFields();
foreach (FieldInfo field in fields)
{
    dgvList.Columns.Add(field.Name, field.Name);
    columns.Add(field.Name, "F");
}

The solution contains six projects - the Dictionary Visualizer for 2005 and 2008, the List Visualizer for 2005 and 2008, the testing project ListVisualizerTest, and the class library that does most of the work, VisualizerLib. ListVisualizerTest is used to debug different types of Lists and Dictionaries and is also used to create the UI for the visualizers.

History

  • 15th April, 2008: Initial post
  • 3rd July, 2010: Article updated - created the new visualizer for Visual Studio 2010
  • 26th August, 2011: Article updated - visualizer for all Visual Studio versions can now be resized

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here