是否可以更改Visual Studio Debugger变量窗口中显示的第三方类的值列? [英] Is it possible to change what is displayed in a Visual Studio Debugger Variables window Value column for a 3rd party class?
问题描述
调试时有各种变量窗口(汽车,本地,包含列名称,值,类型。
该值通常似乎显示一个对象的类名。在具体情况下,我想根据类实例的属性显示更有意义的东西。
When debugging there are various Variable windows (autos, locals, watch) containing columns Name,Value,Type. The value often seems to show an object's class name. In specific cases I would like to show something more meaningful based on the properties of the class instance.
作为一个具体例子,对于 CodeTypeReference 我想看到引用的类型的文本表示(有效),基于 BaseType 字符串或 ArrayElementType 值,而不是看到System.CodeDom.CodeTypeReferenceExpression。
As a specific example, for CodeTypeReference I'd like to see a text representation of the type referenced (where valid) based on the BaseType string or ArrayElementType value, rather than seeing "System.CodeDom.CodeTypeReferenceExpression".
可视化程序似乎提供单独的对话窗口,而不是填充值列的方式。
Visualizers seem to offer separate dialog windows, rather than a way to populate the value column.
数据提示是每个变量而不是每个类型。
Data tips are per variable rather than per type.
最近的事情似乎是 DebuggerTypeProxyAttribute 在这种情况下,我想我问可以将某个属性应用于别人的类吗?
The closest thing seems to be the DebuggerTypeProxyAttribute in which case I guess I'm asking "Is it possible to apply an attribute to somebody else's class ?"
我主要处理Visual Studio 2010,尽管Visual Studio 2008的答案将会很有用。
I'm mainly dealing with Visual Studio 2010 although a Visual Studio 2008 answer would be useful.
推荐答案
是有两种方法可以实现这一点:
Yes, there are two ways you can accomplish this:
-
使用 Visual Studio的BugAid ,这是我创建的商业工具,您可以简单地 star 属性/您的类型上的字段,并且这些字段出现在任何类型的值列中,无论是否为第三方。
By using BugAid for Visual Studio, a commercial tool that I created, you can simply star properties/fields on your type, and have those appear in the Value column on any type, whether it is 3rd party or not.
您可以更改autoexp.cs文件,并应用 DebuggerDisplayAttribute 或DebuggerTypeProxyAttribute到第三方类型,如我的答案一个类似的问题。例如,您将如何将DebuggerDisplayAttribute应用于System.Drawing.Pen: [assembly:DebuggerDisplay(@\ {Color = {color}},Target = typeof(Pen))]
You can change your autoexp.cs file, and apply either the DebuggerDisplayAttribute or the DebuggerTypeProxyAttribute to 3rd party types, as described in my answer on a similar question. For example, this is how you would apply the DebuggerDisplayAttribute to System.Drawing.Pen: [assembly: DebuggerDisplay(@"\{Color = {color}}", Target = typeof(Pen))]
此答案适用于VS2008和VS2010。
This answer applies to both VS2008 and VS2010.
这篇关于是否可以更改Visual Studio Debugger变量窗口中显示的第三方类的值列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!