Visual Studio中的监视窗口

问题描述:

是否有一种方法可以指定要在监视窗口"中查看的对象的哪些成员,而无需使用所有属性扩展树.例如:

Is there a way to specify what members of an object to see in Watch Window without expanding the tree with all the properties. For example:

p =新的Point(10,10)将显示在Watch的值"列中: {X = 10 Y = 10} .

p = new Point(10 ,10) will display on the Value column in Watch : {X = 10 Y = 10}.

对于我自己的类,它始终显示: {MyNamespace.MyClass}或{MyNamespace.MyStruct} .

For my own classes it always displays : {MyNamespace.MyClass} or {MyNamespace.MyStruct}.

我可以更改它以便显示: {MyStringProperty =" MyIntProperty = 0 ...} 吗?

Could I change this in order to display : { MyStringProperty = "" MyIntProperty = 0 ... } ?

请参见使用DebuggerDisplay属性

如果您已通过属性标记班级:

[DebuggerDisplay("x = {X} y = {Y}")]
public class MyClass
{
   public int X { get; private set; }
   public int Y { get; private set; }
}

出现在监视"窗口的值"列中的输出将如下所示:

x = 5 y = 18