• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

c#如何使用 XML 文档功能

c# 搞代码 4年前 (2022-01-09) 27次浏览 已收录 0个评论

下面的示例提供对某个已存档类型的基本概述。

示例

// If compiling from the command line, compile with: -doc:YourFileName.xml

/// <summary>
/// Class level summary documentation goes here.
/// </summary>
/// <remarks>
/// Longer comments can be associated with a type or member through
/// the remarks tag.
/// </remarks>
public class TestClass : TestInterface
{
  /// <summary>
  /// Store for the Name property.
  /// </summary>
  private string _name = null;

  /// <summary>
  /// The class constructor.
  /// </summary>
  public TestClass()
  {
    // TODO: Add Constructor Logic here.
  }

  /// <summary>
  /// Name property.
  /// </summary>
  /// <value>
  /// A value tag is used to describe the property value.
  /// </value>
  public string Name
  {
    get
    {
      if (_name == null)
      {
        throw new System.Exception("Name is null");
      }
      return _name;
    }
  }

  /// <summary>
  /// Description for SomeMethod.
  /// </summary>
  /// <param name="s"> Parameter description for s goes here.</param>
  /// <seealso cref="System.Strin<strong>本文来源gaodai#ma#com搞@@代~&码*网2</strong>g">
  /// 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 values 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;
  }

  public int InterfaceMethod(int n)
  {
    return n * n;
  }

  /// <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;
  }
}

/// <summary>
/// Documentation that describes the interface goes here.
/// </summary>
/// <remarks>
/// Details about the interface go here.
/// </remarks>
interface TestInterface
{
  /// <summary>
  /// Documentation that describes the method goes here.
  /// </summary>
  /// <param name="n">
  /// Parameter n requires an integer argument.
  /// </param>
  /// <returns>
  /// The method returns an integer.
  /// </returns>
  int InterfaceMethod(int n);
}

该示例生成一个包含以下内容的 .xml 文件。

<?xml version="1.0"?>
<doc>
  <assembly>
    <name>xmlsample</name>
  </assembly>
  <members>
    <member name="T:TestClass">
      <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:TestClass._name">
      <summary>
      Store for the Name property.
      </summary>
    </member>
    <member name="M:TestClass.#ctor">
      <summary>
      The class constructor.
      </summary>
    </member>
    <member name="P:TestClass.Name">
      <summary>
      Name property.
      </summary>
      <value>
      A value tag is used to describe the property value.
      </value>
    </member>
    <member name="M:TestClass.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:TestClass.SomeOtherMethod">
      <summary>
      Some other method.
      </summary>
      <returns>
      Return values are described through the returns tag.
      </returns>
      <seealso cref="M:TestClass.SomeMethod(System.String)">
      Notice the use of the cref attribute to reference a specific method.
      </seealso>
    </member>
    <member name="M:TestClass.Main(System.String[])">
      <summary>
      The entry point for the application.
      </summary>
      <param name="args"> A list of command line arguments.</param>
    </member>
    <member name="T:TestInterface">
      <summary>
      Documentation that describes the interface goes here.
      </summary>
      <remarks>
      Details about the interface go here.
      </remarks>
    </member>
    <member name="M:TestInterface.InterfaceMethod(System.Int32)">
      <summary>
      Documentation that describes the method goes here.
      </summary>
      <param name="n">
      Parameter n requires an integer argument.
      </param>
      <returns>
      The method returns an integer.
      </returns>
    </member>
  </members>
</doc>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:c#如何使用 XML 文档功能
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址