VisualStudio 或 .Net Framework 中已经存在哪些 DebuggerVisualizer? [英] What DebuggerVisualizers are already existing within VisualStudio or .Net Framework?

查看:29
本文介绍了VisualStudio 或 .Net Framework 中已经存在哪些 DebuggerVisualizer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个很愚蠢的问题,但我就是找不到答案.

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

我有一个自己编写的类,它实现了 IList 接口.现在我喜欢在 Debugging 中看到包含元素,就像我在任何 .Net List 中看到的一样.

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>.

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

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.

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

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?

推荐答案

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

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(); }
}

这也适用于 .NET 4.0,即使版本号是错误的.否则,如果他们决定重命名内部类,这将有可能与 .NET 的下一版本中断.

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.

这篇关于VisualStudio 或 .Net Framework 中已经存在哪些 DebuggerVisualizer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆