Display properties in custom order in Visual Studio Debugger

In Visual Studio, can I set the order in which properties are displayed when checking in the debugger?

Here is an example of a class where I would really like StartDate and EndDate to appear next to each other, although they are separated alphabetically.

example

Other debugger options are configured using attributes such as DebuggerDisplayAttribute, so I was hoping that another such attribute would exist for DisplayOrder.

[DebuggerDisplay("{Name}")]
public class Rule
{
    public string Name;
    public int MaxAge;
    public DateTime StartDate;
    public DateTime EndDate;
}

In an ideal world, I would like to order properties in the inspector in the order that I defined in the class (even if this requires setting the debugger order attribute for each property), so the display will look like this:

ideal debugger

+4
3

JCL, DebuggerTypeProxyAttribute, ,

API .

DebuggerTypeProxy:

[DebuggerDisplay("{Name}")]
[DebuggerTypeProxy(typeof (RuleDebugView))]
public class Rule
{
    public string Name;
    public int MaxAge;
    public DateTime StartDate;
    public DateTime EndDate;

    internal class RuleDebugView
    {
        public string _1_Name;
        public int _2_MaxAge;
        public DateTime _3_StartDate;
        public DateTime _4_EndDate;

        public RuleDebugView(Rule rule)
        {
            this._1_Name = rule.Name;
            this._2_MaxAge = rule.MaxAge;
            this._3_StartDate = rule.StartDate;
            this._4_EndDate = rule.EndDate;
        }
    }
}

:

debugger

, .

+1

JCL, #if DEBUG . , , :

[DebuggerDisplay("{Name}")]
public class Rule
{
    public string Name;
    public int MaxAge;
    public DateTime StartDate;
    public DateTime EndDate;

#if DEBUG
    private string DateRange
    {
        get { return StartDate.ToString("dd/MM/yyyy") + " - "+
                     EndDate.ToString("dd/MM/yyyy");
        } 
    }
#endif

}

:

debugger

, , .

+2

You can right-click on the variables and add hours and put them in order.

enter image description here

+1
source

All Articles