VisualStudio 或 .Net Framework 中已经存在哪些 DebuggerVisualizer?
这是一个非常愚蠢的问题,但我根本找不到答案。
我有一个自己编写的类,它实现了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
.NET 框架类使用的调试器可视化工具是内部的。这使得它们有点难以使用,你不能使用 typeof()。虽然有一个后门,[DebuggerTypeProxy] 属性也有一个接受字符串的构造函数。您要使用的名为 Mscorlib_CollectionDebugView,它能够可视化任何实现 ICollection<> 的类。下面是一个用法示例:
这也适用于 .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:
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.
List
使用DebuggerTypeProxyAttribute
定义调试器的代理。您可以使用以下表达式找到所有内容:使用上述表达式,您还可以测试 DebuggerVisualizerAttribute,但这给出零结果(可能是因为未引用特定文件夹中的程序集)。如果引用文件夹中的程序集,则可以使用上面的表达式来查找其中的实现。
List<T>
uses theDebuggerTypeProxyAttribute
to define a proxy for the debugger. You can find all using the following expression: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.有一篇关于如何制作自己的列表调试器的好文章:
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
您可以使用参数中的可视化工具类型向类
System.Diagnostics.DebuggerVisualizerAttribute
添加属性You can add an attribute to you class
System.Diagnostics.DebuggerVisualizerAttribute
with the visualizer type in argument