Creating a Visualizer C # VS2010 that works on all objects

I am trying to create a C # debugging visualizer that can perform visualization on all objects. It seems I cannot get the assembly attribute (above the namespace) to bind this visualizer to a System.Object, like Ive, with other objects in the system. I searched in detail, but did not find examples / discussions about creating a visualizer for all objects. Here is the Im code trying to work, it works quite well when attached to String or Int32, but not to an object or object.

[assembly: System.Diagnostics.DebuggerVisualizer( typeof(Visualizers.ObjectVisualizer), typeof(Visualizers.RawObjectScource), Target = typeof(object), Description = "Object Visualizer")] namespace Visualizers { public class ObjectVisualizer : DialogDebuggerVisualizer { override protected void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) { Console.Out.WriteLine("InShow"); MessageBox.Show(objectProvider.GetObject().ToString()); } } // handle any object, doesn't require that it Serializable public class RawObjectScource : VisualizerObjectSource { public override void GetData(object target, Stream outgoingData) { if (target != null) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(outgoingData, target.ToString()); } } } } 

As a former Java programmer who used IntelliJ Im, used to seeing in debug mode what the heap address pointed to by a particular link points to. This allows you to see immediately if two objects are referenced. In addition, there are several other things that would be valuable to understanding, but they may be a little long to explain. If I can get it to work, I have to post the final code.

So does anyone know how to make the visualizer be active for all objects?

+4
source share
1 answer

I do not know what bad code. however @Bismark, the goal should not be serialized, as you can use your own VisualizerObjectSource to serialize it

I suggest you serialize .GetType().AsseblyQualifierName along .GetType().AsseblyQualifierName it, this will let you specify which object the stream contains, so when deserializing you know that object acutaly is an instance of class x , I used this method, one of my own visualizers , because sometimes you can serialize a class subtype during the deserialization process, which you do not know about how long you have been working.

0
source

All Articles