Csharp/C Sharp/Development Class/XML Documentation
Содержание
How to write the Xml based document
using System;
using System.Collections.Generic;
using System.Text;
namespace XmlDocCar
{
/// <summary>
/// This is a simple Car.
/// </summary>
public class Car
{
/// <summary>
/// Do you have a sunroof?
/// </summary>
private bool hasSunroof = false;
/// <summary>
/// The ctor lets you set the sunroofedness.
/// </summary>
/// <param name="hasSunroof"></param>
public Car(bool hasSunroof)
{
this.hasSunroof = hasSunroof;
}
/// <summary>
/// This method allows you to open your sunroof.
/// </summary>
/// <param name="state"> </param>
public void OpenSunroof(bool state)
{
if (state == true && hasSunroof == true)
Console.WriteLine("has sub roof!");
else
Console.WriteLine("you don"t have a sunroof.");
}
}
}
set up project with one file containing the <include> tag
namespace SimpleXML
{
/// <include file="supporting.xml"
/// path="MyDocs/MyMembers[@name="Class1"]/*" />
class Class1
{
public static void Main() {}
}
/// <include file="supporting.xml"
/// path="MyDocs/MyMembers[@name="Class2"]/*" />
class Class2
{
public void Foo() {}
}
}
Use summary element
namespace SimpleXML
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args) {}
/// <summary>
/// This method does something interesting.
/// </summary>
public static void Foo() {}
}
}
XML based comments
using System;
/// <summary>
/// Main method.
/// <para>This sample is useless.</para>
/// </summary>
class SayHello {
/// <summary>
/// This is the Main method for the class and is
/// the execution starting point for our application.
/// Please note that <paramref name="args">args</paramref>
/// is a array of strings.
/// </summary>
/// <param name="args">params for Main method</param>
/// <returns>Returns a value depending on how the program
/// was called.</returns>
//We want Main to return an integer.
public static int Main(string[] args) {
if (args.Length > 0) {
return (0);
}
return (1);
}
}
XML Documentation: Compiler Support Tags
using System;
namespace Payroll
{
/// <summary>
/// Comments for the class
/// This class class contains a <see cref="String">string</see>
/// </summary>
public class Employee
{
/// <summary>
/// Constructor for an Employee instance. Note that
/// <paramref name="name">name2</paramref> is a string.
/// </summary>
/// <param name="id">Employee id number</param>
/// <param name="name">Employee Name</param>
public Employee(int id, string name)
{
this.id = id;
this.name = name;
}
/// <summary>
/// Parameterless constructor for an employee instance
/// </summary>
/// <remarks>
/// <seealso cref="Employee(int, string)">Employee(int, string)</seealso>
/// </remarks>
public Employee()
{
id = -1;
name = null;
}
int id;
string name;
}
}