Generate comments of the Net object in 1 minute

Source: Internet
Author: User

 

During the development process, we will certainly have several projects as the basic projects and store some commonly used classes and methods for other projects. in general, after the implementation of the method, I don't want to worry about it any more, so that a new guy asks whether the methods in this project have been commented or explained. The general answer is all. after that, we will all know and will not describe it any more.

In fact, there are many methods to generate comments for classes or interfaces in the project. A few days ago, I also saw a CHM help document using Sandcastle software to generate DLL files, I am also using this software to generate API documentation. The address is not found. if you are interested, you can search for the software. This article does not focus on how to use the software.

Next, let's talk about the business scenario. Based on the customer's business needs, we need to display the class attributes or method lists in a class library in the NET program for the customer to view, as shown in-1.

Figure-1

The reflection method can be used to generate a simple structure as shown in. If we show it to the customer in this way, what are the customer's opinions? After a long period of patience to teach and explain how to use these methods, the customer finally failed to do so .... Well, I don't know if you should be happy or sad?

OK. Now that the business scenario is ready, we have to find a solution to it? At first, the method I used was implemented through the custom Attribute of the Net Attribute. In short, the idea is to create the classes shown in-2, and all these classes inherit from the Attribute class.

Figure 2

Currently, these classes define two attributes: DisplayText and Descrip, that is, the Chinese display name and descriptive text of each object, as shown in-3. in this way, we can obtain the custom attribute information of a class or method through reflection. This method solves most of our problems and can be basically implemented. however, it needs to add the custom attribute class we just created to each class or method in the DLL file, and the workload is indeed not small. in addition, when describing the parameter information of a method, it is difficult to edit Custom Attributes due to the uncertainty of the number of parameters. in the end, this method is Over and not adopted.

Figure-3

A few days ago, we suddenly remembered that we could directly generate an XML file by commenting on the classes or methods in the DLL, that is, in the configuration item of the DLL generation, check the XML injection ention file option, it will generate the XML comment file for this DLL file. -4

Figure 4

Let's take a look at the XML file format, as shown in-5.

Figure 5

Parsing this XML file is just a child, and what we need to do is to complete the annotation information of each class or method, instead of using custom attributes to record comments. if you have a good habit of commenting on classes or methods, congratulations. your task has been completed. resolution Method-6 shows that the file I provided is complete and can be downloaded directly.

Figure 6

Let's take a look at the resolution results, as shown in-7. after obtaining the following data, you can search for it in the reflection process, including the class name, method name, and parameter name required by the method.

 

Source File: http://www.bkjia.com/uploadfile/2011/1031/20111031055533857.rar

 

 

Author Vincent. Q

<Script> </script>

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.