Geek Speak: Follow-up Debugging and Tweaking Week (Part 3 of 5): Visual Studio 2005 Debugging Enhancements
Today's Slides : Click Here
Articles
- Create a Debugger Visualizer Using Visual Studio 2005 Beta 1
ms-help://MS.MSDNQTR.2005JAN.1033/dnvs05/html/simplevisualizercreation.htm - DataTips, Visualizers and Viewers Make Debugging .NET Code a Breeze
Sample Code:
NETMatters0408.exe -- VS 2003 Code
VS2005 Code:
Visualizers
Testing Visualizers
VS2005 Visualizer Code Construction
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.VisualStudio.DebuggerVisualizers;
namespace MyVisual
{
// TODO: Add the following to SomeType's defintion to see this visualizer when debugging instances of SomeType:
//
// [DebuggerVisualizer(typeof(Visualizer1))]
// [Serializable]
// public class SomeType
// {
// ...
// }
//
/// <summary>
/// A Visualizer for SomeType.
/// </summary>
public class Visualizer1 : DialogDebuggerVisualizer
{
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
{
// TODO: Get the object to display a visualizer for.
// Cast the result of objectProvider.GetObject()
// to the type of the object being visualized.
object data = (object)objectProvider.GetObject();
// TODO: Display your view of the object.
// Replace displayForm with your own custom Form or Control.
Form displayForm = new Form();
displayForm.Text = data.ToString();
windowService.ShowDialog(displayForm);
}
// TODO: Add the following to your testing code to test the visualizer:
//
// Visualizer1.TestShowVisualizer(new SomeType());
//
/// <summary>
/// Tests the visualizer by hosting it outside of the debugger.
/// </summary>
/// <param name="objectToVisualize">The object to display in the visualizer.</param>
public static void TestShowVisualizer(object objectToVisualize)
{
VisualizerDevelopmentHost visualizerHost = new VisualizerDevelopmentHost(objectToVisualize, typeof(Visualizer1));
visualizerHost.ShowVisualizer();
}
}
}