Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Use DebuggerBrowsable Attribute for a better view in debugger window

, 4 Feb 2010
Rate this:
Please Sign up or sign in to vote.
There are lots of simple tricks in .net which can be very useful if you used wisely. In this post I want to discuss the use of DebuggerBrowsableAttribute. Using this attribute you can control how a member of class will be displayed in debugger windows during debugging. Before that consider small...
There are lots of simple tricks in .net which can be very useful if you used wisely. In this post I want to discuss the use of DebuggerBrowsableAttribute. Using this attribute you can control how a member of class will be displayed in debugger windows during debugging. Before that consider small example:
 
public class Customer
    {
 
        public string CustomerId
        {
            set;
            get;
        }
        public string CustomerName
        {
            set;
            get;
        }
        public string CustomerLocation
        {
            set;
            get;
        }
        public string CustomerGuid
        {
            set;
            get;
        }
    }
Lets create a instance of Organization and add some sample data:
 
List<Customer> customers = new List<Customer>();
customers.Add(new Customer { CustomerId = "1", CustomerName = "BenCustomer", CustomerLocation = "New York", CustomerGuid = System.Guid.NewGuid().ToString() });
customers.Add(new Customer { CustomerId = "2", CustomerName = "JonhCustomer", CustomerLocation = "London", CustomerGuid = System.Guid.NewGuid().ToString() });
customers.Add(new Customer { CustomerId = "3", CustomerName = "HarryCustomer", CustomerLocation = "Sydney", CustomerGuid = System.Guid.NewGuid().ToString() });
customers.Add(new Customer { CustomerId = "4", CustomerName = "CrisCustomer", CustomerLocation = "Kolkata", CustomerGuid = System.Guid.NewGuid().ToString() });
Now when you run this program in debug mode and try to view the customers in debugger window .
 

Lets try to change it using DebuggerBrowsableAttribute. Make following changes by adding DebuggerBrowsableAttribute:
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public string CustomerGuid
{
   set;
   get;
}
Again run this program in debug mode and try to view the customers in debugger window. Now You can see how “CustomerGuid” is gone out.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Palash Biswas
Software Developer Kovair Inc.
India India
I have started programming in 10 years on Fortran 77.Then it was Cobol,C,C++,JAVA 1.2, ASP,JavaScript. Now it at all C# and .NET Framework, such tehnologies as WCF, ADO.NET, ASP.NET, LINQ, ASP.NET Ajax , FLEX and another.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 4 Feb 2010
Article Copyright 2010 by Palash Biswas
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid