简体   繁体   English

创建一个对所有Object进行操作的C#VS2010 Visualizer

[英]Creating a C# VS2010 Visualizer that operates on all Object

I'm attempting to create a C# debugging visualizer that can perform a visualization on all objects. 我正在尝试创建一个可以对所有对象执行可视化的C#调试可视化工具。 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. 我似乎无法获得程序集属性(在命名空间上方)将此可视化程序绑定到System.Object,就像我已经能够与系统中的其他对象一样。 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. 这是我正在努力工作的代码,它在绑定到String或Int32时运行良好,但不是Object或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. 作为一名使用IntelliJ的前Java程序员,我习惯于在调试模式下看到堆地址是特定引用所指向的。 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? 那么有谁知道如何使可视化器对所有对象都有效?

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 但是@Bismark,目标不需要序列化,因为你可以使用自己的VisualizerObjectSource来对其进行sesialize

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. 我建议你按顺序搜索.GetType().AsseblyQualifierName ,这将允许你包含流所包含的对象类型,所以在反序列化时你知道你的对象是acutaly类x一个实例,我用这个技术一个我自己的可视化器有时候你可能会在反序列化中序列化一个类的子类型,你不知道你在什么时候使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM