0

Say I have the following two classes:

[DebuggerDisplay("Test={Test}")]
class Class1
{
    public string Test;
}

[DebuggerDisplay("obj={obj}")]
class Class2
{
    public Class1 obj;
}

class Program
{
    public static void Main(string[] args)
    {
        var c1 = new Class1() { Test = "test" };
        var c2 = new Class2() { obj = c1 };
    }
}

Is it possible to enable the debugger display of Class2 to show the debugger display of Class1? I.e., I would like hovering over c2 to reveal obj="test".

rookie
  • 2,783
  • 5
  • 29
  • 43

1 Answers1

1

you can write in this style for your goal:

[DebuggerDisplay("{ToString()}")]
class Class1
{
    public string Test;
    public override string ToString()
    {
        return "Test=" + Test;
    }
}

[DebuggerDisplay("{ToString()}")]
class Class2
{
    public Class1 obj;
    public override string ToString()
    {
        return "obj=" + obj;
    }
}

internal class Program
{
    public static void Main(string[] args)
    {
        var c1 = new Class1() {Test = "test"};
        var c2 = new Class2() {obj = c1};
    }
}
burning_LEGION
  • 13,246
  • 8
  • 40
  • 52