Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DebuggerDisplayAttribute for property/field

I have a class with a property of standard type. In debugger I would like to see this particular property in some specific format. I'm using attribute DebuggerDisplay on that particular property, but in debugger's Watch window I see it applied to entire class, but not to target property. What am I missing?

class Transaction : ITransaction
{
    [DebuggerDisplay("{DateAsDebugString}")]
    public DateTime Date
    {
        get;set;
    }

    string DateAsDebugString
    {
        get
        {
            var res = Date.ToShortDateString();
            if (Date.TimeOfDay != TimeSpan.Parse("00:00"))
                res += " " + Date.TimeOfDay.ToString();
            return res;
        }
    }

}

enter image description here

How to apply property level debugger formatting/visualizing rules?

like image 738
Philipp Munin Avatar asked Dec 03 '25 17:12

Philipp Munin


1 Answers

This seems to be a bug in Visual Studio 2015, as documented here. Unfortunately it doesn't seem to have ever been fixed.

The same code in Visual Studio 2013 produces the expected results.

like image 52
Bradley Uffner Avatar answered Dec 06 '25 06:12

Bradley Uffner