• DebuggerDisplay和DebuggerTypeProxy


    DebuggerDisplay和DebuggerTypeProxy是两个属性,用来在VS调试的状态下,显示一些额外的信息,方便用户进行调试。

    DebuggerDisplay 不单能够显示变量的值,还能调用变量的方法来计算结果显示:

    class Program
        {
            static void Main(string[] args)
            {
                Company c = new Company();
    
                Console.ReadLine();
            }
        }
    
        [DebuggerDisplay("company name:{name}, employee count:{employeeNames.Count}")]
        class Company
        {
            public string name = "Company1";
    
            List<string> employeeNames = new List<string>() { "Employee1", "Employee2", "Employee3" };
        }

    image

    DebuggerTypeProxy 可以附加一些属性在VS调试窗口中,提供了更加灵活的方式。如果DebugView中的属性和类型本身的属性名字相同,那么类型的属性将会被覆盖,在VS调试器中看不见了。

    class Program
        {
            static void Main(string[] args)
            {
                Company2 c2 = new Company2();
                Debugger.Break();
                Console.ReadLine();
            }
        }
    
        [DebuggerTypeProxy(typeof(Company2DebugView))]
        class Company2
        {
            internal class Company2DebugView
            {
                private Company2 m_Company2;
    
                //必须要有一个构造函数,包含目标类型
                public Company2DebugView(Company2 company2)
                {
                    m_Company2 = company2;
                }
    
                public string Employees
                {
                    get
                    {
                        return String.Join(" | ", m_Company2.employeeNames.ToArray());
                    }
                }
            }
    
            private string name = "Company2";
    
            private List<string> employeeNames = new List<string>() { "Employee1", "Employee2", "Employee3" };
        }

    image

  • 相关阅读:
    L-这是最难的题(二分+前缀和)
    SPFA 原理剖析代码实现分析比较
    树状数组---原理代码实现
    bellman-ford算法
    UML用例图总结
    UML类图几种关系的总结
    UML序列图总结
    线段树--Color the ball(多次染色问题)
    临时文档3
    POJ2676-Sudoku(数独)
  • 原文地址:https://www.cnblogs.com/haoxinyue/p/2943317.html
Copyright © 2020-2023  润新知