Two tips for custom debugging forms in Visual Studio

Source: Internet
Author: User

This articleArticleDescribes how to customize your debugging form. These skills are used to debug the application.ProgramIs very useful. When debugging, you may want to simplify the debugging form information, or remove unnecessary information that is not important to you from the debugging form. This article will help you. Few Tips on customizing debugging window view in Visual Studio.

You can use the debuggerbrowsable feature to customize the debugging form.

You can use the debuggerdisplay feature to customize the display of debugging information.

To use these features, you must reference the system. Diagnostics namespace.

Tip 1: Use the debuggerbrowsable feature

You can use the debuggerbrowsable feature on the property to customize the debugging form. These features can be used on any attribute, field, or index. The debuggerbrowsable constructor requires a debuggerbrowsablestate parameter. Debuggerbrowsablestate is used to specify how debugging information is displayed on the form.

It has three states:

1. collapsed: If debuggerbrowsablestate is set to collapsed. The debugging information is collapsed and displayed. The default value is collapsed.

2. Never: the debugging form does not display debugging information.

3. roothidden: hides the root element of the debugging information and only displays the child element information. For more information, see msdn.

The following example describes how to use debuggerbrowsable and debuggerbrowsablestate. Before you start, read the following section.Code:

Class program {static void main (string [] ARGs) {list <student> Student = new list <student> (); student. add (New Student {roll = 1, name = "Abhijit", marks = 87, addresses = new address {address1 = "Add1", address2 = "Add2 "}}); student. add (New Student {roll = 2, name = "Abhishek", marks = 41, addresses = new address {address1 = "add3", address2 = "add4 "}}); student. add (New Student {roll = 3, name = "Rahul", marks = 67, addresses = new address {address1 = "add5", address2 = ""}); student. add (New Student {roll = 4, name = "Sunil", marks = 91, addresses = new address {address1 = "add11", address2 = "add122 "}}); student. add (New Student {roll = 5, name = "Atul", marks = 71, addresses = new address {address1 = "add12", address2 = "add222 "}}); student. add (New Student {roll = 6, name = "Kunal", marks = 71, addresses = new address {address1 = "add12", address2 = "add222 "}});} /// <summary> /// student class /// </Summary> class student {public int roll {Get; set;} public string name {Get; set ;} public int marks {Get; set;} public address addresses {Get; Set ;}} /// <summary> // address of students // </Summary> Class address {Public String address1 {Get; set;} Public String address2 {Get; set ;}}}

Next, let's take a look at the effect of not using these features. I place a breakpoint at the end of the main function. You can get the following debugging form.

We can see that there are 6 Student objects, each of which has different values.AddressesIt is an object of Address class, and its debugging information value is hidden.

Now, I want to see all the attributes of the address and hide the marks attribute. To achieve this, you need to add the debuggerbrowsable feature to the marks and addresses attributes of the student class.

Debugging information is displayed as follows:

Tip 2: Use the debuggerdisplay feature

You can use debuggerdisplay to define how classes and fields are displayed in the debugging form. You can use debuggerdisplay to change the information and variables displayed in the debugging form so that it displays the information you want.

It is not used belowDebuggerdisplayDebugging form.

By default, you only getDisplay information such as namespace. classname. We can useDebuggerdisplay is used to customize the displayed information. DebuggerdisplayThe name of the constructor must be displayed as a parameter. You can pass the specified parameter for display. Make the following settings:

See the following results:

When using debuggerdisplay, note that the correct attributes of the class must be provided in.

For example, if I write roll as rolls, for example:

The debug form prompts the name 'rolls' does not exist in the current context. For example:

 

Summary:This article describes how to use the debuggerbrowsable and debuggerdisplay features to customize the display of debugging forms. When you debug a very complex object, this is very useful, it can make your debugging form very simple.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.