本文介绍了在复杂类型链接DebuggerDisplay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个类定义DebuggerDisplay属性。我想知道是否有一种方法来定义基于另一个一一DebuggerDisplay属性。如果我有以下类:

I have several classes defining the DebuggerDisplay attribute. I want to know if there is a way to define one DebuggerDisplay attribute based on another one. If I have the following classes:

[DebuggerDisplay ("Text = {Text}")]
class A
{
    public string Text {get;set;}
}

[DebuggerDisplay ("Property = {Property}")]
class B
{
    public A Property {get; set;}
}

我想对A类,因为它是在A级DebuggerDisplay属性定义的B实例看。那相反,我得到了A类的ToString()方法到调试器,一边欣赏B类对象。

I would like to see on instances of B the A class as it is defined on the class A DebuggerDisplay attribute. Instead of that I'm getting the class A ToString() method onto the debugger while viewing class B objects.

推荐答案

不知道我是否正确地理解你的问题,但尝试:

Not sure if I understood your problem correctly but try:

[DebuggerDisplay("Property = {Property.Text}")]
public class B
{
    public A Property { get; set; }
}

这将显示A的Text属性。

This will Display the A's Text property.

如果您需要更复杂的控制,你可以使用 DebuggerTypeProxyAttribute

If you need more complex control you can use DebuggerTypeProxyAttribute

这篇关于在复杂类型链接DebuggerDisplay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!