Custom Visual Studio debugging window

Source: Internet
Author: User

Inspired by yuanyou Qilin's article, I studied the technologies related to the custom debugging window and found that it was very simple, but it helped greatly improve the debugging efficiency, in the past, debugging and display of complex data was crazy, either not displaying (only displaying a type), or looking at it layer by layer. If you can customize the debugging window, it would be nice to display the data as expected. I will introduce the implementation method in detail below.

Step 1: Create a console application and add a reference to Microsoft. visualstudio. debuggervisualizers.

Step 2: create a new class that we want to display the custom debugging window information during debugging.CodeFor example, create a class mytable backup.

Step 3: create a new class mytabledebuggervisualizer. This class inherits dialogdebuggervisualizer, which is in the namespace Microsoft. visual Studio. in debuggervisualizers, this abstract class has only one show method for the user to implement. The two parameters of this method are idialogvisualizerservice and ivisualizerobjectprovider. The former is used to control the display of visualizer (forms, etc, the latter provides debugging data, as well as replacement and data transmission methods.

Step 4: Create the winform window mytabledebuggerviewform, which will be used to display debugging data. Mytabledebuggervisualizer is only an access point. to display your debugging window, you only need to use the showdialog method provided by idialogvisualizerservice to display mytabledebuggerviewform. Of course, you can also pass in the data to be debugged.

1:UsingMicrosoft. visualstudio. debuggervisualizers;
 
2:
 
3:NamespaceCustomdebugger
 
4 :{
5:Public ClassMytabledebuggervisualizer: dialogdebuggervisualizer
 
6 :{
 
7:Protected Override VoidShow (idialogvisualizerservice windowservice,
8: ivisualizerobjectprovider objectprovider)
 
9 :{
 
10:// Todo: Get the object to display a Visualizer.
 
11:// Cast the result of objectprovider. GetObject ()
12:// To the type of the object being visualized.
 
13: mytable = (mytable) objectprovider. GetObject ();
 
14:// Todo: Display your view of the object.
15:// Replace displayform with your own M form or control.
 
16: mytabledebuggerviewform displayform =NewMytabledebuggerviewform (mytable );
 
17: windowservice. showdialog (displayform );
 
18 :}
19 :}
 
20 :}

Step 5: Associate the debugging window information with the class mytable, and use the debuggervisualizer attribute under system. diagnostics to set the visual components for mytable.

 
1: [debuggervisualizer (Typeof(Mytabledebuggervisualizer)]
 
2: [serializable]
3:Public ClassMytable
 
4 :{
 
5 :}

Note that the serializable attribute on mytable requires the class to be serializable in the Custom debugging window. Therefore, if serializable is added, I guess this is required, from the methods provided by ivisualizerobjectprovider, we found that getdata exists in addition to GetObject, while getdata returns stream, which requires that the object to be debugged must be serializable.

To see the effect, add some display code in mytabledebuggerviewform.

1:PublicPartialClassMytabledebuggerviewform: Form
 
2 :{
 
3:PublicMytabledebuggerviewform (mytable)
 
4 :{
5:This. Table = mytable;
 
6: initializecomponent ();
 
7 :}
 
8:
9:PublicMytable table {Get;Private Set;}
 
10:
 
11:Private VoidMytabledebuggerviewform_load (ObjectSender, eventargs E)
12 :{
 
13:This. Text =This. Table. tostring ();
 
14 :}
 
15 :}

Now you can debug it. Define a mytable in the main function, set a breakpoint, and debug it.

Did you see that small magnifier? Slam it

The custom window is displayed and the title is mytable type name. Is it very easy. Finally, you can display the debugged data as needed,ArticleAt the end, I will provide a complete example for your reference. Finally, it is important to note about debugging.

Debugging the "debugging window" is similar to debugging the control designer or Visual Studio plug-in. If you have experience developing the control designer, you should have thought about debugging, the following is a brief explanation of how to debug the SDK:

On the properties page of the project, find the debug settings, set the start action of the project to start external program, select the exefile devenv.exe of visual studio, and save the settings. Then, press the breakpoint in mytabledebuggerviewform_load method of mytabledebuggerviewform to start debugging. A New Visual Studio is opened and the same project is opened in the new IDE, it is slightly different from the debugging control designer. In this case, you need to change the debugging option of the project back to the start project in the new IDE (otherwise, another IDE will be opened after debugging ), in the new IDE, set the breakpoint (in mytable) and debug mytable. When the custom debugging window is opened, the breakpoint of the first IDE is hit.

Finally, I would like to share with you the complete debugging window :)

Is it similar to the debugging window of datatable? I hope this article will help you.

Download complete code

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.