首页 > 其他 > 详细

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

时间:2019-07-01 21:07:57      阅读:129      评论:0      收藏:0      [点我收藏+]
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 { }
}

 

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

原文:https://www.cnblogs.com/zhuwansu/p/11116581.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!