VisualStudio 或 .Net Framework 中已经存在哪些 DebuggerVisualizer?

发布于 2024-10-15 20:44:52 字数 404 浏览 12 评论 0原文

这是一个非常愚蠢的问题,但我根本找不到答案。

我有一个自己编写的类,它实现了 IList 接口。现在,我希望看到调试中包含的元素,就像使用任何 .Net List 一样。

为了让它工作,我想我必须在 DebuggerVisualizerAttribute 中提供正确的可视化工具。经过一番搜索后,我能找到的只是附加可视化工具的文件夹。但数据集只有一个。

但是 Visual Studio 中已经可用的所有可视化工具的类型是什么(例如字符串、列表等),以便我可以为我已经可用的东西的实现提供正确的类型?

A quite dumb question but i simply can't find the answer.

I have a self-written class that implements the IList<T> interface. Now i like to see the containing elements within Debugging like i would with any .Net List<T>.

To get this to work i think i have to provide the correct visualizer within the DebuggerVisualizerAttribute. After a little searching all i could find is the folder for additional Visualizer. But there is just one for the DataSet.

But what are the types of all the Visualizer already available within Visual Studio (e.g. for string, List, etc.), so that i could provide the correct one for my implementation of something already available?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

画▽骨i 2024-10-22 20:44:52

.NET 框架类使用的调试器可视化工具是内部的。这使得它们有点难以使用,你不能使用 typeof()。虽然有一个后门,[DebuggerTypeProxy] 属性也有一个接受字符串的构造函数。您要使用的名为 Mscorlib_CollectionDebugView,它能够可视化任何实现 ICollection<> 的类。下面是一个用法示例:

[DebuggerTypeProxy("System.Collections.Generic.Mscorlib_CollectionDebugView`1, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
class MyCollection<T> : IList<T> {
    private List<T> impl = new List<T>();
    public int IndexOf(T item) {  return impl.IndexOf(item); }
    public void Insert(int index, T item) { impl.Insert(index, item); }
    public void RemoveAt(int index) { impl.RemoveAt(index); }
    public T this[int index] {
        get { return impl[index]; }
        set { impl[index] = value; }
    }
    public void Add(T item) { impl.Add(item); }
    public void Clear() { impl.Clear(); }
    public bool Contains(T item) { return impl.Contains(item); }
    public void CopyTo(T[] array, int arrayIndex) { impl.CopyTo(array, arrayIndex); }
    public int Count { get { return impl.Count; }}
    public bool IsReadOnly { get { return ((System.Collections.IList)impl).IsReadOnly; }}
    public bool Remove(T item) { return impl.Remove(item); }
    public IEnumerator<T> GetEnumerator() { return impl.GetEnumerator(); }
    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
}

这也适用于 .NET 4.0,即使版本号错误。否则,如果他们决定重命名内部类,则存在与 .NET 的下一版本中断的风险。

The debugger visualizers used by the .NET framework classes are internal. Which makes them a bit hard to use, you cannot use typeof(). There's a backdoor though, the [DebuggerTypeProxy] attribute also has a constructor that accepts a string. The one you want to use is named Mscorlib_CollectionDebugView, it is capable of visualing any class that implements ICollection<>. Here's an example of usage:

[DebuggerTypeProxy("System.Collections.Generic.Mscorlib_CollectionDebugView`1, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
class MyCollection<T> : IList<T> {
    private List<T> impl = new List<T>();
    public int IndexOf(T item) {  return impl.IndexOf(item); }
    public void Insert(int index, T item) { impl.Insert(index, item); }
    public void RemoveAt(int index) { impl.RemoveAt(index); }
    public T this[int index] {
        get { return impl[index]; }
        set { impl[index] = value; }
    }
    public void Add(T item) { impl.Add(item); }
    public void Clear() { impl.Clear(); }
    public bool Contains(T item) { return impl.Contains(item); }
    public void CopyTo(T[] array, int arrayIndex) { impl.CopyTo(array, arrayIndex); }
    public int Count { get { return impl.Count; }}
    public bool IsReadOnly { get { return ((System.Collections.IList)impl).IsReadOnly; }}
    public bool Remove(T item) { return impl.Remove(item); }
    public IEnumerator<T> GetEnumerator() { return impl.GetEnumerator(); }
    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
}

This works for .NET 4.0 as well, even though the version number is wrong. This otherwise has a risk of breaking with the next version of .NET if they decide to rename the internal class.

π浅易 2024-10-22 20:44:52

List 使用 DebuggerTypeProxyAttribute 定义调试器的代理。您可以使用以下表达式找到所有内容:

var types =
    from assembly in AppDomain.CurrentDomain.GetAssemblies()
    from type in assembly.GetTypes()
    from attribute in type.GetCustomAttributes(typeof(DebuggerTypeProxyAttribute), true)
    select ((DebuggerTypeProxyAttribute)attribute).ProxyTypeName;

使用上述表达式,您还可以测试 DebuggerVisualizerAttribute,但这给出零结果(可能是因为未引用特定文件夹中的程序集)。如果引用文件夹中的程序集,则可以使用上面的表达式来查找其中的实现。

List<T> uses the DebuggerTypeProxyAttribute to define a proxy for the debugger. You can find all using the following expression:

var types =
    from assembly in AppDomain.CurrentDomain.GetAssemblies()
    from type in assembly.GetTypes()
    from attribute in type.GetCustomAttributes(typeof(DebuggerTypeProxyAttribute), true)
    select ((DebuggerTypeProxyAttribute)attribute).ProxyTypeName;

With the above expression, you can also test for DebuggerVisualizerAttribute, but this gave zero results (probably because the assemblies in the specific folder are not referenced). If you reference the assemblies in the folder, you can use the above expression to find the implementations there.

乖乖哒 2024-10-22 20:44:52

有一篇关于如何制作自己的列表调试器的好文章:

http://www.codeproject .com/KB/debug/DebugIList.aspx

There is a nice article about how to make your own List debugger:

http://www.codeproject.com/KB/debug/DebugIList.aspx

勿忘心安 2024-10-22 20:44:52

您可以使用参数中的可视化工具类型向类 System.Diagnostics.DebuggerVisualizerAttribute 添加属性

You can add an attribute to you class System.Diagnostics.DebuggerVisualizerAttribute with the visualizer type in argument

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文