Plunging into .NET Development

Weblog Pieter Gheysens
Microsoft .NET Development - C# - Enterprise Library - Visual Studio 2005 Team System - Compuware DevPartner - ...

Tuesday, September 6

Custom Visualizers in VS 2005

Visualizers are a new component of the Visual Studio 2005 debugger user interface. A visualizer creates a dialog box or other interface to display a variable or object in a meaningful way that is appropriate to its data type.

Out of the box there are four standard visualizers :
  • Text Visualizer
  • HTML Visualizer
  • XML Visualizer
  • Dataset Visualizer
The first tree work on string objects while the Dataset Visualizer which works for DataSet, DataView, and DataTable objects.

Visualizers are represented in the debugger by a magnifying glass icon. When you see the magnifying glass icon, you can click on it to select a visualizer appropriate to the data type of the corresponding object.

I included a preview of the HTML Visualizer ...

At TechEd 2005 in Amsterdam, I attended the session What's new in the Visual C# 2005 IDE, given by Juval Lowy. I remembered that he showed us a custom sound visualizer and I was pretty impressed how easy it was to create one on your own for a custom class. So I tried it out tonight ...

I created a class Player with some properties (FirstName, LastName, Image, ...) and for that class I wanted to create a custom Visualizer : PlayerVisualizer (see example below). The custom form (visualizer) displays an image of the player and some other player-information.

While debugging I'm now able to see a custom view of the Player object. No more playing around in the command/immediate window to query for the info you're looking for. Just clicking the magnifying glass to call the custom visualizer. Cool, isn't it?

All I had to do was :
  1. Adding a Debugger Visualizer Template to my project

  2. Creating a custom form to display the info I wanted and how I wanted it.
  3. Adapting the template (Show-method)
    • casting to a Player object
    • passing Player object to custom form
    • show custom form
  4. Adding the DebuggerVisualizerAttribute to tell the debugger about the classes that make up the visualizer
More info on how to do this exactly (code) can be found in this excellent article (Creating a Debugger Visualizer) on the MSDN-website.


Post a Comment

Links to this post:

Create a Link

<< Home