Click here to Skip to main content

Use DebuggerBrowsable Attribute for a better view in debugger window

Sign Up to vote bad good
Add a reason or comment to your vote: x
Votes of 3 or less require a comment
See more: C#
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.
Posted 4 Feb '10
Edited 4 Feb '10


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

Your Filters
Interested
Ignored
     
  1. SAKryukov (895)
  2. CRDave1988 (264)
  1. SAKryukov (10,992)
  2. Christian Graus (7,218)
  3. OriginalGriff (5,439)
  4. Abhinav S (4,615)
  5. thatraja (4,526)

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --

Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 4 Feb 2010
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid