5,427,303 members and growing! (15,189 online)
Email Password   helpLost your password?
General Programming » Macros and Add-ins » VS.NET Add-ins     Intermediate License: The Code Project Open License (CPOL)

A Generic List and Dictionary Debugger Visualizer for VS.NET

By Daniel Carvalho Liedke

A cool List and Dictionary debugger visualizer for VS.NET 2005 and 2008.
C# (C# 2.0, C# 3.0, C#), VB (VB 8.0, VB 9.0, VB), .NET (.NET, .NET 2.0), Visual Studio (VS2008, VS2005, Visual Studio), Dev

Posted: 15 Apr 2008
Updated: 15 Apr 2008
Views: 6,006
Bookmarked: 26 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
15 votes for this Article.
Popularity: 5.44 Rating: 4.63 out of 5
0 votes, 0.0%
1
1 vote, 6.7%
2
0 votes, 0.0%
3
2 votes, 13.3%
4
12 votes, 80.0%
5

ListVisualizer2008

Introduction

This is a simple List<T> and Dictionary<T,T> debugger visualizer for Visual Studio .NET 2005 and 2008. 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 or List Visualizer 2008 according to the Visual Studio .NET version you would like to use. Run install_vs2005.cmd or install_vs2008.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) and c:\Program Files\Microsoft Visual Studio 9.0 (for VS.NET 2008). 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 and in 2008 is c:\Program Files\Microsoft Visual Studio 9.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.

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Daniel Carvalho Liedke


I work with development for 15 years now, since MSX basic. Started Windows programming with VB 2.0 and Web programming with ASP 3.0. Now I build Windows Forms, Web Applications and NT services using Microsoft.NET. I am MCP in Visual Basic 6.0, MCAD and MCSD.NET in Framework 1.1 and MCTS Web in Framework 2.0. Besides programming I love surfing.
Occupation: Web Developer
Location: Brazil Brazil

Other popular Macros and Add-ins articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralWhat about custom lists?memberQwertie13:09 18 Jul '08  
GeneralRe: What about custom lists?memberDaniel Carvalho Liedke5:42 19 Jul '08  
GeneralRe: What about custom lists?memberQwertie6:33 19 Jul '08  
GeneralRe: What about custom lists?memberDaniel Carvalho Liedke17:32 19 Jul '08  
GeneralGreat!membermerlin9814:57 16 Apr '08  
GeneralRe: Great!memberDaniel Carvalho Liedke7:02 16 Apr '08  
GeneralNice to include an install script, but...memberOregonGhost23:53 15 Apr '08  
GeneralRe: Nice to include an install script, but...memberDaniel Carvalho Liedke3:02 16 Apr '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 Apr 2008
Editor: Smitha Vijayan
Copyright 2008 by Daniel Carvalho Liedke
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project