Class to create custom debugging information, let your debugger is faster and more convenient

Original: class to create custom debugging information, to make your debugging more convenient

We are using a set of classes in your application, you want to quickly see the value of the class in the debugger. The debugger will not show the information to customize the class by default.
At this point we can add features to a DebuggerDisplay class. At this time, the debugger will display the information you want. as follows
   [DebuggerDisplay("User Full Name={Id} {Name} {Age}")]
    public class User  
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int  Age { get; set; }
    }
test:
 
     static void Main(string[] args)
        {
            List<User> users = new List<User>();
            users.Add(new User() { Id = 1, Name = "张三", Age = 10 });
            users.Add(new User() { Id = 2, Name = "李四", Age = 11 });
            var otherUsers = users;
            List<string> list = new List<string>();
        }
Facie display:
Stuttgart is not the effect of this:
Of course, if they think you want one of the above properties are written on a little trouble, DebuggerDisplay characteristics can also access this pointer directly, but use this pointer to access any of the properties will not attribute properties were evaluated before treatment.
 [DebuggerDisplay("User Full Name={this}")]
    public class User  
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int  Age { get; set; }
    }
 
Of course the above manner, you need to override the ToString method:
 public override string ToString()
        {
            return $"{Id} {Name} {Age}";
        }
 
If you do not get through the above value you need, you just need to Tools -> Options -> Debug, and then check the arrow is pointing:
 

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/10966063.html