c# - 如何将 Visual Studio Text Visualizer 用于自定义类型?

标签 c# visual-studio debuggervisualizer

在 Visual Studio 2015(以及一些旧版本)中调试 C# 代码时,可以通过拖放在各种可视化工具(文本、XML、HTML、JSON)中显示 string 变量的值-带有放大镜图标的下拉列表。这也适用于某些非字符串类型,例如 System.Xml.Linq.XElement。是否可以使用这些内置的可视化工具来显示我自己的自定义类型的变量值?

上下文:

我需要能够快速检查复杂的自定义类型的状态,该类型只能在多行 文本环境中可视化。

最佳答案

如果我正确理解你的问题,那么你可以用 DebuggerTypeProxy 实现你想要的。 .它会导致调试器在您检查复杂类型的对象时创建并显示代理对象。

在下面的示例中,代理对象包含一个(多行)字符串属性,您可以使用文本可视化工具查看该属性。如果您仍然需要查看底层对象本身,那么这就是 Raw view 按钮的用途。

[DebuggerTypeProxy(typeof(ComplexTypeProxy))]
class ComplexType
{
    // complex state
}

class ComplexTypeProxy
{
    public string Display
    {
        get { return "Create a multi-line representation of _content's complex state here."; }
    }

    private ComplexType _content;

    public ComplexTypeProxy(ComplexType content)
    {
        _content = content;
    }
}

关于c# - 如何将 Visual Studio Text Visualizer 用于自定义类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41764714/

相关文章:

c# - 调试二叉树

c# - Nunit 2.6 + Resharper 7 +NCrunch + visual studio 2010

c# - 为什么 catch (Exception) 错误?

c++ - error LNK2019 函数中引用的未解析外部符号dbbind

C:如何使 ArrayList 实现与 UNICODE_STRING 数据兼容?

visual-studio - 从 Visual Studio 调试器获取变量

c# - 以DateTime为目标的调试可视化器不会传输该值

c# - 如何将数据表从 C# 传递到 SQL Server 存储过程

c# - 如何仅在填充上面行的特定单元格后才向 datagridview 添加新行?

visual-studio - TODO:任务列表中未显示注释