Possible to accessing child “DebuggerDisplay” attribute of property?

前端 未结 3 890
温柔的废话
温柔的废话 2021-02-19 22:49

Current state

Having two classes:

[DebuggerDisplay(@"One = {One}, two = {Two}")]
public class A
{
    public int One { get; set; }
    public B         


        
3条回答
  •  悲&欢浪女
    2021-02-19 23:32

    Copied possible solution from OP

    Probably, my requirement is not possible as per this SO answer. Maybe a good solution would be to override ToString in class B and do some if..else and use the Debugger.IsAttached property to behave different only inside the debugger.

    Something like:

    [DebuggerDisplay(@"Three = {Three}")]
    public class B
    {
        public int Three { get; set; }
    
        public override string ToString()
        {
            if (Debugger.IsAttached)
            {
                return string.Format(@"Three = {0}", Three);
            }
            else
            {
                return base.ToString();
            }
        }
    }
    

提交回复
热议问题