简体   繁体   English

如何在Visual Studio中指定调试器可视化器的顺序

[英]How to specify order of debugger visualizers in Visual Studio

I've been working on a debugger visualizer for Visual Studio for some time and while the actual visualizer works fine. 我一直在为Visual Studio的调试器可视化器工作一段时间,而实际的可视化工作正常。 The problem is that it always places itself at the top of the visualizer list when examining a variable which really annoys some of the users who rather have Text as the top one (since the top one is also default when opening VS). 问题是,在检查变量时,它始终将自己置于可视化列表的顶部,这些变量确实使一些用户更喜欢将Text作为顶级用户(因为在打开VS时,前者也是默认值)。

在此输入图像描述

I can't find any support for this on DialogDebuggerVisualizer or DebuggerVisualizerAttribute which were my first thoughts so I've been scouring SO/MSDN/Google for information on how to affect the sort order of the visualizers (preferably to put mine last in the list) but to no avail. 我在DialogDebuggerVisualizerDebuggerVisualizerAttribute上找不到任何支持,这是我的第一个想法,所以我一直在搜索SO / MSDN / Google,了解如何影响可视化器的排序顺序(最好将我的最后一个放在列表中) )但无济于事。

Below is how I register my visualizer, it then just shows a form based on the value that is being visualized. 下面是我如何注册我的可视化工具,然后它只显示一个基于可视化值的表单。

using Microsoft.VisualStudio.DebuggerVisualizers;

[assembly: System.Diagnostics.DebuggerVisualizer(
    typeof(Shorthand.VSAddins.JsonVisualizer.JsonVisualizer),
    typeof(VisualizerObjectSource),
    Target = typeof(string),
    Description = "Json Visualizer")]
namespace Shorthand.VSAddins.JsonVisualizer
{
    public class JsonVisualizer : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            var json = objectProvider.GetObject() as string;

            var form = new VisualizerForm { Json = json };
            windowService.ShowDialog(form);
        }
    }
}

Does anyone know if it is possible to affect the order of the visualizers or should I just let it be? 有谁知道是否有可能影响可视化器的顺序,还是应该让它成为现实?

I don't think there is a solution. 我认为没有解决方案。 But there is a workaround: 但有一个解决方法:

Define your own Text Visualizer and put appropriate DebuggerVisualizer attribute before the attribute of your JsonVisualizer . 定义自己的Text Visualizer并在JsonVisualizer属性之前放置适当的DebuggerVisualizer属性。 The result will be that string will be readable by default and Json Visualizer can be chosen. 结果是默认情况下该字符串是可读的,并且可以选择Json Visualizer。 A window with a multi-line textbox is not too much work. 具有多行文本框的窗口不是太多工作。

It is probably not even necessary to write visualizer. 甚至可能不需要编写可视化工具。 It should be possible to use internal one but I don't know its name ( Which class is used for "Text Visualizer"? ). 应该可以使用内部的一个,但我不知道它的名称( 哪个类用于“Text Visualizer”? )。

It will always appear first, by design. 它总是首先出现在设计上。 The under the hood cast has found the best match for the variable it is reflecting on. 引擎盖下的演员已经找到了它所反映的变量的最佳匹配。

however, you could do either of two things. 但是,你可以做两件事。 You could make the visualizer only appear when the sting contains ':' Or you could use reflection to reorder the visualisers by adding them to the end of the collection in the order you want, then removing the originals from the collection. 您可以仅在sting包含':'时显示可视化工具。或者您可以使用反射按顺序将可视化工具按顺序添加到集合的末尾,然后从集合中删除原件。 For the latter you will most likely have to change the collection from readonly to writable. 对于后者,您很可能必须将集合从只读更改为可写。 Via reflection. 通过反思。

There is no reliable source to draw on other than your will to succeed. 除了你的成功意愿之外,没有可靠的消息来源。

I guess that VS 'under the hood' can distinguish between type of string and type of xml quite easily, but Xml is just a string too, so a key question here would be, how does VS tell the difference between the two? 我猜VS'引擎盖'可以很容易地区分字符串的类型和xml的类型,但是Xml也只是一个字符串,所以这里的一个关键问题是,VS如何区分两者之间的区别?

Could you dissect the VS XML visualizer to see how it works (even if you have to use reflector on the DLL to do it, you might get to see the method that works it out) 您是否可以剖析VS XML可视化工具以查看它是如何工作的(即使您必须在DLL上使用反射器来执行此操作,您可能会看到可以解决的方法)

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

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