5、调试显示应该使用 DebuggerDisplay 而不是误用 ToString

using System.Diagnostics;

namespace ShouldCode.Console
{

    [DebuggerDisplay("Prop1:{Prop1};Prop2:{Prop2};")]
    public class ShouldDebuggerDisplay {
        public int Prop1 { get; set; }
        public string Prop2 { get; set; }

        public static void Debug()
        {
            var debugger1 = new ShouldDebuggerDisplay
            {
                Prop1 = 1,
                Prop2 = "2"
            };

            var debugger2 = new NotToString
            {
                Prop1 = 1,
                Prop2 = "2"
            };
            var debugger3 = new DefaultDisplay();
            //ojbect is object 
            var defDisplay = typeof(DefaultDisplay).FullName;
            var tostring = debugger3.ToString();
            
            // breakpoint here to see debugger 
            System.Console.ReadLine();
        }
    }
    public class NotToString
    {
        public int Prop1 { get; set; }
        public string Prop2 { get; set; }

        public override string ToString()
        {
            return $"Prop1:{Prop1};Prop2:{Prop2};";
        }
       
    }

    public class DefaultDisplay { }
}

猜你喜欢

转载自www.cnblogs.com/zhuwansu/p/11116581.html
今日推荐