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.
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.