What DebuggerVisualizers already exist in VisualStudio or the .NET Framework?

A very stupid question, but I just can't find the answer.

I have a self-written class that implements an interface IList<T>. Now I like to see the contained elements in Debugging, as I would with any .Net List<T>.

To make this work, I think I have to provide the right visualizer in DebuggerVisualizerAttribute. After a little search of everything I could find, a folder for an additional Visualizer . But there is only one for a DataSet.

But what are the types of all Visualizer already available in Visual Studio (for example, for a string, list, etc.), so that I could provide the correct option for my existing implementation?

+3
source share
4 answers

The debugger visualizers used by .NET clustered classes are internal. Which makes them a little difficult to use, you cannot use typeof (). There is a backdoor there, and the [DebuggerTypeProxy] attribute also has a constructor that takes a string. The one you want to use is called Mscorlib_CollectionDebugView, it is able to render any class that implements ICollection <>. Here is a usage example:

[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 also works for .NET 4.0, although the version number is incorrect. This otherwise runs the risk of hacking with the next version of .NET if they decide to rename the inner class.

+4
source

List<T> 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, (, , ). , , .

+2

class System.Diagnostics.DebuggerVisualizerAttribute

0

Source: https://habr.com/ru/post/1789751/


All Articles