In C # use XML annotation

zhaozj2021-02-16  61

Introduction

Most programmers may have heard of a tool javadoc from Java itself; using it automatically generates an HTML document for your code. The C # and C # compilers also have similar functions, but it generates XML instead of directly generating HTML. However, using XML will make the document more flexible.

Note syntax

In order to use the XML annotation feature provided by C #, your annotation should start using a special annotation syntax (/ / /). After ///, you can use a pre-defined label to comment your code or insert your own defined tag. Your custom label will be added to the generated comment document.

Predefined label

Tag text in the description as code

provides a method of making multi-line instructions as a code

Specify examples of use or other library members

Allows you to specify an exception class that may happen

Allows you to specify a comment in another file that describes the types and members of the source code, use the XML XPath syntax to describe the types and members in your source code.

Insert a list into the XML comment document

Insert a paragraph into the XML comment document

describes a parameter

provides a method indicating a word as a parameter

Allows you to add members' access licenses to your document

is used to add information about a type

Description Return Value

Specify link

Specifies the text you want to appear in the "See" section

Type or type member general description

Description Property

example

The following example adds a comment for our common HelloWorld console applications:

Using system; namespace helloworld {///

/// Sample Hello World in C # /// public class helloworld {/// /// console application entry point /// Command line arguments /// status code of 0 on successful run /// public static int main (string [] args) {system.console .Writeline ("HelloWorld"); string name = system.console.readline (); return (0);}}} To generate an XML comment document, we use the / doc option when calling CSC compiling source code:

CSC /DOC: HelloWorld.xml HelloWorld.cs

The resulting result document is as follows:

XMLComment

Sample Hello World in C #

Console Application Entry Point

Command Line Arguments

Status Code of 0 on successful run

HTML page

You may ask yourself: How should I get the HTML page with a good format? Very simple, you can write your own XSL to convert the generated XML comment document, or use the Visual Studio.net development tool. By using the [Generate Note Web Page] in the [Tools] menu of VS.NET, you can get a series of detailed description of your project or solution HTML page. Below is the HTML page snapshot of the HELLOWORLD program generated by vs.net:

转载请注明原文地址:https://www.9cbs.com/read-23424.html

New Post(0)