zoukankan      html  css  js  c++  java
  • 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();
                //调试时显示窗口的值是 type.fullname 其中 ojbect is object 
                var defDisplay = typeof(DefaultDisplay).FullName;
                var tostring = debugger3.ToString();//ShouldCode.Console.DefaultDisplay
                
                // 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 { }
    }
  • 相关阅读:
    lufylegend:图形变形3
    javascript: Math.sin() cos() 用法
    lufylegend:图形变形2
    lufylegend:图形变形1
    lufylegend:图片的加载和显示
    lufylegend基础知识1
    canvas使用3
    canvas使用2
    canvas使用1
    javascript:addEventListener
  • 原文地址:https://www.cnblogs.com/zhuwansu/p/11116581.html
Copyright © 2011-2022 走看看