logo
CSharp_Prog_Guide

Использование xml-документации

В следующем примере приводятся общие сведения о документированном типе.

Пример

------

/// <summary>

/// Description for SomeMethod.</summary>

/// <param name="s"> Parameter description for s goes here</param>

/// <seealso cref="System.String">

/// You can use the cref attribute on any tag to reference a type or member

/// and the compiler will check that the reference exists. </seealso>

public void SomeMethod(string s)

{

}

/// <summary>

/// Some other method. </summary>

/// <returns>

/// Return results are described through the returns tag.</returns>

/// <seealso cref="SomeMethod(string)">

/// Notice the use of the cref attribute to reference a specific method </seealso>

public int SomeOtherMethod()

{

return 0;

}

/// <summary>

/// The entry point for the application.

/// </summary>

/// <param name="args"> A list of command line arguments</param>

static int Main(System.String[] args)

{

// TODO: Add code to start application here

return 0;

}

}

-------

// This .xml file was generated with the previous code sample.

<?xml version="1.0"?>

<doc>

<assembly>

<name>xmlsample</name>

</assembly>

<members>

<member name="T:SomeClass">

<summary>

Class level summary documentation goes here.</summary>

<remarks>

Longer comments can be associated with a type or member

through the remarks tag</remarks>

</member>

<member name="F:SomeClass.m_Name">

<summary>

Store for the name property</summary>

</member>

<member name="M:SomeClass.#ctor">

<summary>The class constructor.</summary>

</member>

<member name="M:SomeClass.SomeMethod(System.String)">

<summary>

Description for SomeMethod.</summary>

<param name="s"> Parameter description for s goes here</param>

<seealso cref="T:System.String">

You can use the cref attribute on any tag to reference a type or member

and the compiler will check that the reference exists. </seealso>

</member>

<member name="M:SomeClass.SomeOtherMethod">

<summary>

Some other method. </summary>

<returns>

Return results are described through the returns tag.</returns>

<seealso cref="M:SomeClass.SomeMethod(System.String)">

Notice the use of the cref attribute to reference a specific method </seealso>

</member>

<member name="M:SomeClass.Main(System.String[])">

<summary>

The entry point for the application.

</summary>

<param name="args"> A list of command line arguments</param>

</member>

<member name="P:SomeClass.Name">

<summary>

Name property </summary>

<value>

A value tag is used to describe the property value</value>

</member>

</members>

</doc>

-----

Compiling the Code

To compile the example, type the following command line:

csc XMLsample.cs /doc:XMLsample.xml

This will create the XML file XMLsample.xml, which you can view in your browser or by using the TYPE command.

Robust Programming

XML documentation starts with ///. When you create a new project, the wizards put some starter /// lines in for you. The processing of these comments has some restrictions:

Note:

The XML file does not provide full information about the type and members (for example, it does not contain any type information). To get full information about a type or member, the documentation file must be used together with reflection on the actual type or member.