Freigeben über


Geek Speak: What is a Visualizer?

Here is the stuff from today’s webcast.

Sample Template for a Visualizer

 

using

System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.VisualStudio.DebuggerVisualizers;

namespace MyFirstVisualizer
{

// 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.

using (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();
}
}
}

Comments