Type Visualizers : Visualizing non-serializable types.
Well thank you PShaffer for your comment. You can indeed create type visualizers for non-serializable types using the Microsoft.VisualStudio.VisualizerObjectSource class. This object is responsible for serializing the type, in binary, from Visual Studio (debugee) to the Type Visualizer (debugger).
Fairly straightforward, to do your own serialization create a custom class that inherits from this class and override the GetData(object target, Stream outgoingData) method. Target is the object being debugged and the outgoingData stream is where you serialize the object too, this stream is what is passed to the overloaded Show() method of the visualizer.
When you use the DebuggerVisualizerAttribute to map your visualizer to the type you use an overload that accepts as a parameter the custom VisualizerObjectSource and this is used instead of the default. aka...
[assembly: DebuggerVisualizer(typeof(XmlDebugTypeVisualizer.XmlTypeVisualizer),
typeof(XmlDebugTypeVisualizer.XmlVisualizerObjectSource),
Target= typeof(System.Xml.XmlDocument), Description="View String as DOM tree")]
Visualizer Architecture
How to: Write a Visualizer
It's too late in the day to go updating the XmlVisualizer I posted before so in the meantime here's a better one.
Conchango Xml Visualizer for Visual Studio 2005 (RTM)
Just like to add I do not mind being wrong, so if you find something that I write is incorrect or not quite complete then please do tell me. So that I can correct it and learn some more. Thanks again PShaffer that comment was appreciated.