Click here to Skip to main content
15,896,428 members
Articles / Programming Languages / C#

Building a Visual Studio DebuggerVisualizer with a Custom Serializer

6 May 2008CPOL5 min read 30.2K   87   12  
For most any Serializeable object, making a DebuggerVisualizer is exceeding simple and examples abound. However, if you are trying to build a DebuggerVisualizer for an object which is not Serializable or takes too long to Serialize and Deserialize, things are not quite so simple.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Atalasoft.Imaging;
using Microsoft.VisualStudio.DebuggerVisualizers;

namespace AtalaImageDebuggerVisualizer
{
    public class AtalaImageVisualizer : Microsoft.VisualStudio.
                         DebuggerVisualizers.DialogDebuggerVisualizer
    {

        protected override void Show(Microsoft.VisualStudio.
               DebuggerVisualizers.IDialogVisualizerService windowService,
                Microsoft.VisualStudio.DebuggerVisualizers.
                 IVisualizerObjectProvider objectProvider)
        {
            Stream stm = objectProvider.GetData();
            if (stm.Length != 0)
            {
                BinaryFormatter bf = new BinaryFormatter();
                AtalaImageTransporter imageData = bf.Deserialize(stm) as AtalaImageTransporter;

                if (imageData != null)
                {
                    AtalaImageViewer view = new AtalaImageViewer(imageData);
                    view.ShowDialog();
                }
            }
        }

        public static void TestShowVisualizer(object objectToVisualize)
        {
            VisualizerDevelopmentHost myHost = new VisualizerDevelopmentHost(objectToVisualize, typeof(AtalaImageVisualizer));
            myHost.ShowVisualizer();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer Atalasoft, Inc.
United States United States
At Atalasoft I work with OCR, Raw Image Formats, Exif Data and Pdf Documents. My interests include Machine Learning, Concurrency and Computer Languages.

Comments and Discussions