4

I’m attempting to create a C# debugging visualizer that can perform a visualization on all objects. I can’t seem to get the assembly attribute (above the namespace) to bind this visualizer to System.Object like I’ve been able to with other objects in the system. I've searched at length but haven't found any examples/discussion about creating a visualizer for all objects. Here is the code I’m trying to get working, it works well enough when bound to String or Int32, but not 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's 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());
        }
    }
}
}

Being a former Java programmer that used IntelliJ I’m used to being able to see in debug mode what the heap address is that a specific reference is pointing to. This allows you to see at a glance if two objects are reference equal. Also, there are a few other things that would be valuable to know, but they can be a bit lengthy to explain. If I can get it working I’ll post the final code.

So does anyone know how to get a visualizer to be active for all objects?

Nick
  • 784
  • 8
  • 12
  • Why do you need to know what assembly system.object is in ? I don't see where you are obviously referencing an assembly. – user957902 Oct 07 '11 at 22:05
  • Sorry, I should have used Attribute not reference, editing. – Nick Oct 07 '11 at 22:24
  • If you need to compare 2 objects if they are equal, just use debugger watch window, enter variables names in that and execute "Make Object ID" from popup menu on each of variables. If they have same object id it means they point to same object reference. – psulek Oct 18 '11 at 11:43
  • Correct me if I'm wrong, but shouldn't `Target` property of `DebuggerVisualizer` point to a serializable datatype? – Dmitriy Oct 19 '11 at 07:46

1 Answers1

0

I dont know what is wrong whit your code. however @Bismark, the target does not have tobe serialize able as you can use your own VisualizerObjectSource to sesialize it

I do suggest you serailise the .GetType().AsseblyQualifierName along whit it, this will allow you to what kind of object the stream contains, so at deserialisation you know that you object is acutaly an instance of class x, I used this technique one of my own visualizers as sometimes you might be serialising an sub-type of of the class whilke at the deserialisation you have no idea what time you are working with.

Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62
Jarno
  • 1