gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 09:37:42 26 4
gpt4 key购买 nike

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

我有一个实现 IList<T> 的自写类界面。现在我喜欢在 Debugging 中查看包含的元素,就像使用任何 .Net List<T> 一样。 .

为了让它工作,我认为我必须在 DebuggerVisualizerAttribute 中提供正确的可视化工具.经过一番搜索,我只能找到 the folder for additional Visualizer .但是 DataSet 只有一个。

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

最佳答案

.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 的下一版本中断。

关于.net - VisualStudio 或 .Net Framework 中已经存在哪些 DebuggerVisualizer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4886836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com