什么DebuggerVisualizers已经在VisualStudio中或.Net框架存在? [英] What DebuggerVisualizers are already existing within VisualStudio or .Net Framework?

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

问题描述

一个非常愚蠢的问题,但我根本无法找到答案。

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

我有一个实现了的IList℃的自写类; T> 接口。现在,我希望看到在调试中含有元素,如我会与任何.NET 名单,其中,T>

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 正确的可视化工具。过了一会儿搜索所有我能找到的就是额外的展示台中的文件夹。但是,只有我一个数据集。

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(如字符串,列表等)中已经提供,这样我就可以提供正确的为我执行已有的东西?

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,它能够visualing实现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.

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

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