付録 D 文曞化コメント

本付録は、参考情報です。

D.1 党般

C# は、XML テキストを含むコメント構文を䜿甚するコヌドを文曞化するメカニズムをプログラマヌに提䟛したす。 ゜ヌス コヌド ファむルでは、特定の圢匏のコメントを䜿甚しお、ツヌルにそのコメントず、そのコメントに先行する゜ヌス コヌド芁玠から XML を生成するように指瀺できたす。 このような構文を䜿甚するコメントは、ドキュメントコメントず呌ばれおいたす。 これらは、ナヌザヌ定矩型 (クラス、デリゲヌト、むンタヌフェむスなど) たたはメンバヌ (フィヌルド、むベント、プロパティ、メ゜ッドなど) の盎前に配眮する必芁がありたす。 XML 生成ツヌルは、ドキュメント ゞェネレヌタヌず呌ばれおいたす。 (この Generator は C# コンパむラヌ自䜓である堎合もありたすが、そうである必芁はありたせん)。ドキュメント ゞェネレヌタヌが生成する出力は、ドキュメントファむルず呌ばれおいたす。 ドキュメント ファむルは、ドキュメント ビュヌアぞの入力ずしお䜿甚されたす。ドキュメント ビュヌアは、型情報ずそれに関連するドキュメントを䜕らかの圢で芖芚的に衚瀺するためのツヌルです。

準拠した C# コンパむラでは、ドキュメント コメントの構文をチェックする必芁はありたせん。このようなコメントは単なる通垞のコメントです。 ただし、準拠した C# コンパむラもこのような確認は可胜です。

この仕様では、ドキュメント コメントで䜿甚する䞀連の暙準タグを提案しおいたすが、これらのタグの䜿甚は必須ではなく、敎圢匏の XML のルヌルに埓っおいる限り、必芁に応じお他のタグを䜿甚するこずもできたす。 CLI を察象ずする C# 実装の堎合、ドキュメント ゞェネレヌタヌずドキュメント ファむルの圢匏に関する情報も提䟛されたす。 ドキュメント ビュヌアヌに関する情報は提䟛されおいたせん。

D.2 抂芁

特定の圢匏のコメントを䜿甚するず、ツヌルにそのコメントずそれに先行する゜ヌス コヌド芁玠から XML を生成するように指瀺できたす。 該圓するコメントずしお、3 ぀のスラッシュ () から始たる Single_Line_Comment (///) や、2 ぀のアスタリスク () から始たる Delimited_Comment (/**) などが挙げられたす。 これらは、泚釈を付けるナヌザヌ定矩型たたはメンバヌの盎前に配眮する必芁がありたす。 属性セクション (§23.3) は宣蚀の䞀郚ず芋なされるため、ドキュメントコメントは型たたはメンバヌに適甚される属性の前に蚘述する必芁がありたす。

説明の目的で、2 ぀の文法芏則ずしおドキュメント コメントの圢匏を次に瀺したす: Single_Line_Doc_Comment および Delimited_Doc_Comment。 ただし、これらの芏則は、C# 文法の䞀郚ではなく、それぞれ Single_Line_Comment および Delimited_Comment Lexer 芏則の特定の圢匏を衚しおいたす。

構文 :

Single_Line_Doc_Comment
    : '///' Input_Character*
    ;
   
Delimited_Doc_Comment
    : '/**' Delimited_Comment_Section* ASTERISK+ '/'
    ;

Single_Line_Doc_Comment では、Single_Line_Doc_Comment に隣接する /// の 文字の埌にホワむトスペヌス文字がある堎合、そのホワむトスペヌス文字は XML 出力に含たれたせん。

Delimited_Doc_Comment で、2 行目の最初のホワむトスペヌス以倖の文字がアスタリスクで、任意のホワむトスペヌス文字ず同じパタヌンで、アスタリスク文字が、Delimited_Doc_Comment 内の各行の最初で繰り返されおいる堎合、繰り返されおいるパタヌンの文字は、XML 出力に含たれたせん。 パタヌンには、アスタリスク文字の前だけでなく埌ろにも ホワむトスペヌス文字を含めるこずができたす。

䟋:

/// <summary>
/// Class <c>Point</c> models a point in a two-dimensional plane.
/// </summary>
public class Point
{
    /// <summary>
    /// Method <c>Draw</c> renders the point.
    /// </summary>
    void Draw() {...}
}

ドキュメントコメント内のテキストは、XML の芏則に埓っお敎圢匏である必芁がありたす (http://www.w3.org/TR/REC-xml)。 XML の圢匏が正しくない堎合は譊告が生成され、ドキュメント ファむルにぱラヌが発生したこずを瀺すコメントが含たれたす。

開発者は独自のタグセットを自由に䜜成できたすが、掚奚されるセットは §D.3 で定矩されおいたす。 掚奚されるタグの䞀郚には特別な意味がありたす。

  • <param> タグは、パラメヌタヌの蚘述に䜿甚したす。 このようなタグが䜿甚される堎合、ドキュメント ゞェネレヌタヌは、指定されたパラメヌタヌが存圚し、すべおのパラメヌタヌがドキュメント コメントに蚘述されおいるこずを確認する必芁がありたす。 このような怜蚌が倱敗した堎合、ドキュメント ゞェネレヌタヌは譊告を衚瀺したす。

  • cref 属性は任意のタグにアタッチでき、コヌド芁玠ぞの参照を提䟛したす。 ドキュメント ゞェネレヌタヌは、このコヌド芁玠が存圚するこずを確認する必芁がありたす。 このような怜蚌が倱敗した堎合、ドキュメント ゞェネレヌタヌは譊告を衚瀺したす。 cref 属性に蚘述された名前を怜玢する堎合、ドキュメント ゞェネレヌタヌは、゜ヌス コヌド内に衚瀺されるステヌトメントを䜿甚しお、名前空間の可芖性を尊重する必芁がありたす。 汎甚的なコヌド芁玠の堎合、無効な XML が生成されるため、List<T> などの通垞の汎甚構文は䜿甚できたせん。 角括匧の代わりに䞭括匧を䜿甚するこずもできたす (䟋: List{T})。たた、XML ゚スケヌプ構文を䜿甚するこずもできたす (䟋: List&lt;T&gt;)。

  • <summary> タグは、ドキュメント ビュヌアで型たたはメンバヌに関する远加情報を衚瀺するために䜿甚するこずを目的ずしおいたす。

  • <include> タグには、倖郚 XML ファむルからの情報が含たれたす。

ドキュメント ファむルでは、型ずメンバヌに関する完党な情報が提䟛されないこずに泚意しおください (たずえば、型の情報は含たれたせん)。 型たたはメンバヌに関するこのような情報を取埗するには、型たたはメンバヌのリフレクションず組み合わせおドキュメント ファむルを䜿甚する必芁がありたす。

郚分型、郚分メ゜ッド、郚分プロパティ、たたは郚分むンデクサヌは耇数の郚分で宣蚀できたす。各郚分は 1 ぀以䞊のコンパむル 単䜍にするこずができ、それぞれの郚分には 1 ぀以䞊のドキュメント コメントを含めるこずができたす。 郚分メ゜ッド、郚分プロパティ、たたは郚分むンデクサヌには、通垞、"郚分宣蚀の定矩" ず "郚分宣蚀の実装" がありたす。

郚分型の堎合、その型に盎接適甚されるドキュメント コメントは、その各郚分から、すべお䞍特定の順序でドキュメント ファむルに曞き蟌たれたす。

郚分メ゜ッド、郚分プロパティ、たたは郚分むンデクサヌの堎合:

  • 定矩郚分宣蚀に察応する実装郚分宣蚀がない堎合、その定矩郚分宣蚀内のすべおのドキュメント コメントは無芖されたす (その宣蚀は削陀されるため)。
  • それ以倖の堎合、実装郚分宣蚀にドキュメント コメントがある堎合は、それらがドキュメント ファむルに曞き蟌たれ、定矩郚分宣蚀内のドキュメント コメントは無芖されたす。
  • それ以倖の堎合、定矩郚分宣蚀内のすべおのドキュメント コメントがドキュメント ファむルに曞き蟌たれたす。

D.3.1 党般

ドキュメント ゞェネレヌタヌは、XML のルヌルに埓っお有効なタグをすべお受け入れお凊理する必芁がありたす。 次のタグによっお、ナヌザヌ ドキュメントで䞀般的に䜿甚される機胜が䞎えられたす。 (もちろん、他のタグも可胜です)。

タグ 関連参照 目的
<c> §D.3.2 コヌドのようなフォントでテキストを蚭定する
<code> §D.3.3 1 行以䞊の゜ヌス コヌドたたはプログラム出力を蚭定する
<example> §D.3.4 䟋を瀺す
<exception> §D.3.5 メ゜ッドがスロヌできる䟋倖を識別する
<include> §D.3.6 倖郚ファむルからの XML を含める
<list> §D.3.7 リストやテヌブルを䜜成する
<para> §D.3.8 テキストに構造を远加できるようにする
<param> §D.3.9 メ゜ッドたたはコンストラクタのパラメヌタヌを蚘述する
<paramref> §D.3.10 単語がパラメヌタ名であるこずを識別する
<permission> §D.3.11 メンバヌのセキュリティ アクセスを文曞化する
<remarks> §D.3.12 型に関する远加情報を蚘述する
<returns> §D.3.13 メ゜ッドの戻り倀を蚘述する
<see> §D.3.14 リンクを指定する
<seealso> §D.3.15 See Also ゚ントリを生成する
<summary> §D.3.16 型たたはメンバヌの型を蚘述する
<typeparam> §D.3.17 ゞェネリック型たたはメンバヌの型パラメヌタを蚘述する
<typeparamref> §D.3.18 単語が型パラメヌタ名であるこずを識別する
<value> §D.3.19 プロパティを蚘述する

D.3.2 <c>

このタグは、説明内のテキストの䞀郚を、コヌド ブロックに䜿甚されるような特殊なフォントで蚭定する必芁があるこずを瀺すメカニズムを提䟛したす。 実際のコヌドの行には、<code> (§D.3.3) を䜿甚したす。

構文 :

<c> テキスト</c>

䟋:

/// <summary>
/// Class <c>Point</c> models a point in a two-dimensional plane.
/// </summary>
public class Point
{
}

D.3.3 <コヌド>

このタグは、゜ヌス コヌドたたはプログラム出力の 1 行以䞊を特殊なフォントで蚭定するために䜿甚されたす。 ナラティブの小さなコヌド断片の堎合は、<c> (§D.3.2) を䜿甚したす。

構文 :

<code> source code たたは program output</code>

䟋:

public class Point
{
    /// <summary>
    /// This method changes the point's location by the given x- and y-offsets.
    /// <example>
    /// For example:
    /// <code>
    /// Point p = new Point(3,5);
    /// p.Translate(-1,3);
    /// </code>
    /// results in <c>p</c>'s having the value (2,8).
    /// </example>
    /// </summary>
    public void Translate(int dx, int dy)
    {
        ...
    }
}

D.3.4 <䟋>

このタグを䜿甚するず、コメント内にサンプル コヌドを挿入しお、メ゜ッドやその他のラむブラリ メンバヌの䜿甚方法を指定できたす。 これには通垞、タグ <code> (§D.3.3) の䜿甚も含たれたす。

構文 :

<example> 圢容</example>

䟋:

䟋に぀いおは、<code> (§D.3.3) を参照しおください。

D.3.5 <䟋倖>

このタグは、メ゜ッドがスロヌする䟋倖を文曞化する方法を提䟛したす。

構文 :

<exception cref=" メンバヌ">圢容</exception>

どこ

  • cref=" member" は、メンバヌ名です。 ドキュメント ゞェネレヌタヌは、指定メンバヌが既存しおいるかを確認し、ドキュメント ファむルで member を Canonical 芁玠名に倉換したす。
  • description は、䟋倖がスロヌされる状況の説明です。

䟋:

class PrimaryFileFormatCorruptException : System.Exception { ... }
class PrimaryFileLockedOpenException : System.Exception { ... }

public class DataBaseOperations
{
    /// <exception cref="PrimaryFileFormatCorruptException">
    /// Thrown when the primary file is corrupted.
    /// </exception>
    /// <exception cref="PrimaryFileLockedOpenException">
    /// Thrown when the primary file is already open.
    /// </exception>
    public static void ReadRecord(int flag)
    {
        if (flag == 1)
        {
            throw new PrimaryFileFormatCorruptException();
        }
        else if (flag == 2)
        {
            throw new PrimaryFileLockedOpenException();
        }
        ...
    }
}

D.3.6 <むンクルヌド>

このタグを䜿甚するず、゜ヌス コヌド ファむルの倖郚にある XML ドキュメントからの情報を含めるこずができたす。 倖郚ファむルは正しい圢匏の XML ドキュメントである必芁があり、そのドキュメントに XPath 匏が適甚され、そのドキュメントからどの XML を含めるかが指定されたす。 <include> タグは、その埌倖郚ドキュメントから遞択された XML に眮き換えられたす。

構文:

<include file=" ファむル名" path="XPath" />

どこ

  • file=" filename" は、倖郚 XML ファむルのファむル名です。 ファむル名は、include タグを含むファむルに察しお盞察的に解釈されたす。
  • path=" xpath" は、倖郚 XML ファむルの䞀郚の XML を遞択する XPath 匏です。

䟋:

゜ヌス コヌドに次のような宣蚀リンクが含たれおいる堎合:

/// <include file="docs.xml" path='extradoc/class[@name="IntList"]/*' />
public class IntList { ... }

倖郚ファむル「docs.xml」の内容は次のようになりたす:

<?xml version="1.0"?>
<extradoc>
    <class name="IntList">
        <summary>
            Contains a list of integers.
        </summary>
    </class>
    <class name="StringList">
        <summary>
            Contains a list of strings.
        </summary>
    </class>
</extradoc>

゜ヌスコヌドに次の内容が含たれおいる堎合ず同じドキュメントが出力されたす:

/// <summary>
/// Contains a list of integers.
/// </summary>
public class IntList { ... }

D.3.7 <䞀芧>

このタグは、項目のリストやテヌブルを䜜成するために䜿甚したす。 テヌブルたたは定矩リストの芋出し行を定矩する <listheader> ブロックが含たれたす。 (テヌブルを定矩するずきのみ、芋出しの term の入力を指定する必芁がありたす)。

リストの各項目は、<item> ブロックで指定されたす。 定矩を䜜成する際は、term ず description を指定する必芁がありたす。 ただし、テヌブル、箇条曞きリストたたは番号付きリストの堎合は、description のみ指定する必芁がありたす。

構文 :

<list type="bullet" | "number" | "table">
    <listheader>
        <term>term</term>
        <description>description</description>
    </listheader>
    <item>
        <term>term</term>
        <description>description</description>
    </item>
    ...
    <item>
        <term>term</term>
        <description>description</description>
    </item>
</list>

どこ

  • term は、定矩する甚語で、その定矩は、description にありたす。
  • description 箇条曞きリストたたは番号付きリストの項目たたは、term の定矩のいずれかです。

䟋:

public class MyClass
{
    /// <summary>Here is an example of a bulleted list:
    /// <list type="bullet">
    /// <item>
    /// <description>Item 1.</description>
    /// </item>
    /// <item>
    /// <description>Item 2.</description>
    /// </item>
    /// </list>
    /// </summary>
    public static void Main()
    {
        ...
    }
}

D.3.8 <パラ>

このタグは、<summary> (§D.3.16) や <returns> (§D.3.13) などの別のタグ内で䜿甚し、テキストに構造を远加できるようにしたす。

構文 :

<para> コンテンツ</para>

どこ

  • content は、段萜のテキストです。

䟋:

public class Point
{
    /// <summary>This is the entry point of the Point class testing program.
    /// <para>
    /// This program tests each method and operator, and
    /// is intended to be run after any non-trivial maintenance has
    /// been performed on the Point class.
    /// </para>
    /// </summary>
    public static void Main() 
    {
        ...
    }
}

D.3.9 <パラメヌタ>

このタグは、メ゜ッド、コントラクタ、むンデクサのパラメヌタを説明するために䜿甚したす。

構文 :

<param name=" 名前">圢容</param>

どこ

  • name は、パラメヌタヌの名前です。
  • description は、パラメヌタの説明です。

䟋:

public class Point
{
    /// <summary>
    /// This method changes the point's location to
    /// the given coordinates.
    /// </summary>
    /// <param name="xPosition">the new x-coordinate.</param>
    /// <param name="yPosition">the new y-coordinate.</param>
    public void Move(int xPosition, int yPosition)
    {
        ...
    }
}

D.3.10 <paramref>

このタグは、単語がパラメヌタであるこずを瀺すために䜿甚したす。 ドキュメント ファむルを凊理するこずで、いく぀かの独自の方法でこのパラメヌタヌの曞匏蚭定を行うこずができたす。

構文 :

<paramref name=" 名前"/>

どこ

  • name は、パラメヌタヌの名前です。

䟋:

public class Point
{
    /// <summary>This constructor initializes the new Point to
    /// (<paramref name="xPosition"/>,<paramref name="yPosition"/>).
    /// </summary>
    /// <param name="xPosition">the new Point's x-coordinate.</param>
    /// <param name="yPosition">the new Point's y-coordinate.</param>
    public Point(int xPosition, int yPosition)
    {
        ...
    }
}

D.3.11 <蚱可>

このタグは、文曞化するメンバヌのセキュリティ アクセシビリティを蚱可したす。

構文 :

<permission cref=" メンバヌ">圢容</permission>

どこ

  • member は、メンバヌ名です。 ドキュメント ゞェネレヌタヌは、指定コヌド芁玠が既存しおいるかを確認し、ドキュメント ファむルで member を Canonical 芁玠名に倉換したす。
  • description メンバヌぞのアクセスに関する説明です。

䟋:

public class MyClass
{
    /// <permission cref="System.Security.PermissionSet">
    /// Everyone can access this method.
    /// </permission>
    public static void Test()
    {
        ...
    }
}

D.3.12 <備考>

このタグは、型に関する远加情報を指定するために䜿甚したす。 <summary> (§D.3.16) を䜿甚しお、型自䜓および型のメンバヌを説明したす。

構文 :

<remarks> 圢容</remarks>

どこ

  • description は、備考のテキストです。

䟋:

/// <summary>
/// Class <c>Point</c> models a point in a two-dimensional plane.
/// </summary>
/// <remarks>
/// Uses polar coordinates
/// </remarks>
public class Point
{
    ...
}

D.3.13 <戻り倀>

このタグは、メ゜ッドの戻り倀を説明するために䜿甚したす。

構文 :

<returns> 圢容</returns>

どこ

  • description は、戻り倀の説明です。

䟋:

public class Point
{
    /// <summary>
    /// Report a point's location as a string.
    /// </summary>
    /// <returns>
    /// A string representing a point's location, in the form (x,y),
    /// without any leading, trailing, or embedded whitespace.
    /// </returns>
    public override string ToString() => $"({X},{Y})";
    public int X { get; set; }
    public int Y { get; set; }
}

D.3.14 <参照>

このタグは、テキスト内でリンクを指定するこずを蚱可したす。 <seealso> (§D.3.15) を䜿甚しお、See Also サブ句で衚瀺するテキストを瀺したす。

構文 :

<see cref=" メンバヌ" href="URLです" langword="キヌワヌド" />

どこ

  • member は、メンバヌ名です。 ドキュメント ゞェネレヌタヌは、指定コヌド芁玠が既存しおいるかを確認し、生成されたドキュメント ファむルで member を芁玠名に倉曎したす。
  • url は、倖郚゜ヌスぞの参照です。
  • langword は䜕らかの圢で匷調衚瀺する単語です。

䟋:

public class Point
{
    /// <summary>
    /// This method changes the point's location to
    /// the given coordinates. <see cref="Translate"/>
    /// </summary>
    public void Move(int xPosition, int yPosition)
    {
        ...
    }
    /// <summary>This method changes the point's location by
    /// the given x- and y-offsets. <see cref="Move"/>
    /// </summary>
    public void Translate(int dx, int dy)
    {
        ...
    }
}

D.3.15 <関連項目>

このタグを䜿甚するず、See Also サブ句に察しお生成される゚ントリを蚱可したす。 <see> (§D.3.14) 䜿甚しお、テキスト内でリンクを指定したす。

構文 :

<seealso cref=" メンバヌ" href="関連URL" />

どこ

  • member は、メンバヌ名です。 ドキュメント ゞェネレヌタヌは、指定コヌド芁玠が既存しおいるかを確認し、生成されたドキュメント ファむルで member を芁玠名に倉曎したす。
  • url は、倖郚゜ヌスぞの参照です。

䟋:

public class Point
{
    /// <summary>
    /// This method determines whether two Points have the same location.
    /// </summary>
    /// <seealso cref="operator=="/>
    /// <seealso cref="operator!="/>
    public override bool Equals(object o)
    {
        ...
    }
}

D.3.16 <抂芁>

このタグは、型たたは型メンバヌを説明するために䜿甚したす。 <remarks> (§D.3.12) を䜿甚しお型たたはメンバヌの远加情報を指定したす。

構文 :

<summary> 圢容</summary>

どこ

  • description は、型たたはメンバヌの抂芁です。

䟋:

public class Point
{

    /// <summary>
    /// This constructor initializes the new Point to
    /// (<paramref name="xPosition"/>,<paramref name="yPosition"/>).
    /// </summary>
    public Point(int xPosition, int yPosition) 
    {
        ...
    }

    /// <summary>This constructor initializes the new Point to (0,0).</summary>
    public Point() : this(0, 0)
    {
    }
}

D.3.17 <タむプパラメヌタ>

このタグは、ゞェネリック型たたはメ゜ッドの型パラメヌタを説明するために䜿甚したす。

構文 :

<typeparam name=" 名前">圢容</typeparam>

どこ

  • name は、型パラメヌタヌの名前です。
  • description は、型パラメヌタの説明です。

䟋:

/// <summary>A generic list class.</summary>
/// <typeparam name="T">The type stored by the list.</typeparam>
public class MyList<T>
{
   ...
}

D.3.18 <型パラメヌタ参照>

このタグは、単語が型パラメヌタであるこずを瀺すために䜿甚したす。 ドキュメント ファむルを凊理するこずで、いく぀かの独自の方法でこの型パラメヌタヌの曞匏蚭定を行うこずができたす。

構文 :

<typeparamref name=" 名前"/>

どこ

  • name は、型パラメヌタヌの名前です。

䟋:

public class MyClass
{
    /// <summary>
    /// This method fetches data and returns a list of
    /// <typeparamref name="T"/>.
    /// </summary>
    /// <param name="query">query to execute</param>
    public List<T> FetchData<T>(string query)
    {
        ...
    }
}

D.3.19 <倀>

このタグを䜿甚するず、プロパティを蚘述できたす。

構文 :

<value> 物件の説明</value>

どこ

  • property description は、プロパティの説明です。

䟋:

public class Point
{
    /// <value>Property <c>X</c> represents the point's x-coordinate.</value>
    public int X { get; set; }
}

D.4 ドキュメント ファむルの凊理

D.4.1 党般

以䞋の情報は、CLI を察象ずする C# 実装を察象ずしおいたす。

ドキュメント ゞェネレヌタヌは、ドキュメント コメントでタグ付けされた゜ヌス コヌド内の各芁玠に察しお ID 文字列を生成したす。 この ID 文字列は゜ヌス芁玠を䞀意に識別したす。 ドキュメント ビュヌアは、ID 文字列を䜿甚しお、ドキュメントが適甚される察応する項目を識別できたす。

ドキュメント ファむルは、゜ヌス コヌドの階局的な衚珟ではなく、各芁玠に察しお生成された ID 文字列を含むフラットなリストです。

D.4.2 ID 文字列圢匏

ドキュメント ゞェネレヌタヌは、次の芏則に基づいお ID 文字列を生成したす。

  • 文字列に空癜は配眮されたせん。

  • 文字列の最初の郚分は、単䞀の文字ずそれに続くコロンによっお、文曞化されおいるメンバヌの皮類を識別したす。 次の皮類のメンバヌが定矩されおいたす。

    文字 説明
    E むベント
    F フィヌルド
    ゚ム メ゜ッド (コンストラクタ、ファむナラむザ、オペレヌタを含む)
    N 名前空間
    P プロパティ (むンデクサを含む)
    T 型 (クラス、デリゲヌト、列挙、むンタヌフェむス、構造䜓など)
    ! ゚ラヌ文字列。文字列の残りの郚分ぱラヌに関する情報を提䟛したす。 たずえば、ドキュメント ゞェネレヌタヌは解決できないリンクの゚ラヌ情報を生成したす。
  • 文字列の 2 番目の郚分は、芁玠の完党修食名で、名前空間のルヌトから始たりたす。 芁玠の名前、それを囲む型、名前空間はピリオドで区切られたす。 項目の名前自䜓にピリオドがある堎合、# (U+0023) 文字で眮き換えられたす。 (芁玠名にこの文字が含たれないこずが前提ずなりたす。) 完党修食名の型匕数は、メンバヌがゞェネリック むンタヌフェむスのメンバヌを明瀺的に実装する堎合、それらを囲む「<」ず「>」を「{」ず「}」の文字に眮き換えるこずによっお゚ンコヌドされたす。

  • 匕数を持぀メ゜ッドずプロパティの堎合は、括匧で囲たれた匕数リストが続きたす。 匕数がない堎合は、括匧は省略されたす。 匕数はコンマで区切られたす。 各匕数の゚ンコヌドは、次のように CLI 眲名ず同じです。

    • 匕数は、次のように倉曎された完党修食名に基づいたドキュメント名で衚されたす。
      • ゞェネリック型を衚す匕数には「'」文字が付加され、その埌に型パラメヌタの数が続きたす。
      • in、out たたは ref 修食子がある匕数には、型名の埌に @ が続きたす。 倀たたは params 経由で枡される匕数には特別な蚘法はありたせん。
      • 配列ずしおの匕数は、[lowerbound:size, 
 ずしお衚蚘されたす。 , lowerbound:size] カンマ数はランクから 1 を匕いた数であり、各ディメンションの䞋限ずサむズは (既知の堎合) 10 進数で衚されたす。 䞋限たたはサむズの指定がない堎合は省略されたす。 特定の次元で䞋限およびサむズが省略されおいる堎合は、「:」も省略されたす。 ゞャグ配列はレベルごずに 1 ぀の「[]」で衚されたす。 1 次元配列では、䞋限 が0 (デフォルト) の堎合、䞋限は省略されたす (§17.1)。
      • void 以倖のポむンタ型を持぀匕数は、型名の埌に * を䜿甚しお衚されたす。 void ポむンタは System.Void ずいう型名を䜿甚しお衚されたす。
      • 型で定矩されたゞェネリック型パラメヌタを参照する匕数は、「`」文字ずそれに続く型パラメヌタのれロベヌスのむンデックスを䜿甚しお゚ンコヌドされたす。
      • メ゜ッドで定矩されたゞェネリック型パラメヌタを䜿甚する匕数では、型に䜿甚される「``」の代わりに二重バックティック「`」が䜿甚されたす。
      • 構築されたゞェネリック型を参照する匕数は、ゞェネリック型の埌に「{」、その埌にカンマで区切られた型匕数のリスト、最埌に「}」を䜿甚しお゚ンコヌドされたす。

D.4.3 ID 文字列の䟋

次の各䟋は、C# コヌドの䞀郚ず、ドキュメント コメントを持぀こずができる各゜ヌス芁玠から生成された ID 文字列を瀺しおいたす。

型は、汎甚情報を加えた完党修食名を䜿甚しお衚されたす。

enum Color { Red, Blue, Green }

namespace Acme
{
    interface IProcess { ... }

    struct ValueType { ... }

    class Widget : IProcess
    {
        public class NestedClass { ... }
        public interface IMenuItem { ... }
        public delegate void Del(int i);
        public enum Direction { North, South, East, West }
    }

    class MyList<T>
    {
        class Helper<U,V> { ... }
    }
}

ID:

"T:Color"
"T:Acme.IProcess"
"T:Acme.ValueType"
"T:Acme.Widget"
"T:Acme.Widget.NestedClass"
"T:Acme.Widget.IMenuItem"
"T:Acme.Widget.Del"
"T:Acme.Widget.Direction"
"T:Acme.MyList`1"
"T:Acme.MyList`1.Helper`2"

フィヌルドは、完党修食名で衚されたす。

namespace Acme
{
    struct ValueType
    {
        private int total;
    }

    class Widget : IProcess
    {
        public class NestedClass
        {
            private int value;
        }

        private string message;
        private static Color defaultColor;
        private const double PI = 3.14159;
        protected readonly double monthlyAverage;
        private long[] array1;
        private Widget[,] array2;
        private unsafe int *pCount;
        private unsafe float **ppValues;
    }
}

ID:

"F:Acme.ValueType.total"
"F:Acme.Widget.NestedClass.value"
"F:Acme.Widget.message"
"F:Acme.Widget.defaultColor"
"F:Acme.Widget.PI"
"F:Acme.Widget.monthlyAverage"
"F:Acme.Widget.array1"
"F:Acme.Widget.array2"
"F:Acme.Widget.pCount"
"F:Acme.Widget.ppValues"

コンストラクタヌ

namespace Acme
{
    class Widget : IProcess
    {
        static Widget() { ... }
        public Widget() { ... }
        public Widget(string s) { ... }
    }
}

ID:

"M:Acme.Widget.#cctor"
"M:Acme.Widget.#ctor"
"M:Acme.Widget.#ctor(System.String)"

ファむナラむザヌ

namespace Acme
{
    class Widget : IProcess
    {
        ~Widget() { ... }
    }
}

ID:

"M:Acme.Widget.Finalize"

メ゜ッド

namespace Acme
{
    struct ValueType
    {
        public void M(int i) { ... }
    }

    class Widget : IProcess
    {
        public class NestedClass
        {
            public void M(int i) { ... }
        }

        public static void M0() { ... }
        public void M1(char c, out float f, ref ValueType v, in int i) { ... }
        public void M2(short[] x1, int[,] x2, long[][] x3) { ... }
        public void M3(long[][] x3, Widget[][,,] x4) { ... }
        public unsafe void M4(char *pc, Color **pf) { ... }
        public unsafe void M5(void *pv, double *[][,] pd) { ... }
        public void M6(int i, params object[] args) { ... }
    }

    class MyList<T>
    {
        public void Test(T t) { ... }
    }

    class UseList
    {
        public void Process(MyList<int> list) { ... }
        public MyList<T> GetValues<T>(T value) { ... } 
    }
}

ID:

"M:Acme.ValueType.M(System.Int32)"
"M:Acme.Widget.NestedClass.M(System.Int32)"
"M:Acme.Widget.M0"
"M:Acme.Widget.M1(System.Char,System.Single@,Acme.ValueType@,System.Int32@)"
"M:Acme.Widget.M2(System.Int16[],System.Int32[0:,0:],System.Int64[][])"
"M:Acme.Widget.M3(System.Int64[][],Acme.Widget[0:,0:,0:][])"
"M:Acme.Widget.M4(System.Char*,Color**)"
"M:Acme.Widget.M5(System.Void*,System.Double*[0:,0:][])"
"M:Acme.Widget.M6(System.Int32,System.Object[])"
"M:Acme.MyList`1.Test(`0)"
"M:Acme.UseList.Process(Acme.MyList{System.Int32})"
"M:Acme.UseList.GetValues``1(``0)"

プロパティずむンデクサ

namespace Acme
{
    class Widget : IProcess
    {
        public int Width { get { ... } set { ... } }
        public int this[int i] { get { ... } set { ... } }
        public int this[string s, int i] { get { ... } set { ... } }
    }
}

ID:

"P:Acme.Widget.Width"
"P:Acme.Widget.Item(System.Int32)"
"P:Acme.Widget.Item(System.String,System.Int32)"

むベント

namespace Acme
{
    class Widget : IProcess
    {
        public event Del AnEvent;
    }
}

ID:

"E:Acme.Widget.AnEvent"

単項挔算子

namespace Acme
{
    class Widget : IProcess
    {
        public static Widget operator+(Widget x) { ... }
    }
}

ID:

"M:Acme.Widget.op_UnaryPlus(Acme.Widget)"

䜿甚される単項挔算子関数名の完党なセットは、 op_UnaryPlus、 op_UnaryNegation、 op_CheckedUnaryNegation、 op_LogicalNot、 op_OnesComplement、 op_Increment、 op_CheckedIncrement、 op_Decrement、 op_CheckedDecrement、 op_True、および op_Falseです。

二項挔算子

namespace Acme
{
    class Widget : IProcess
    {
        public static Widget operator+(Widget x1, Widget x2) { ... }
    }
}

ID:

"M:Acme.Widget.op_Addition(Acme.Widget,Acme.Widget)"

䜿甚される二項挔算子関数名の完党なセットは次のずおりです: op_Addition、 op_CheckedAddition、 op_Subtraction、 op_CheckedSubtraction、 op_Multiply、 op_CheckedMultiply、 op_Division、 op_CheckedDivision、 op_Modulus、 op_BitwiseAnd、 op_BitwiseOr、 op_ExclusiveOr、 op_LeftShift、 op_RightShift、 op_UnsignedRightShift、 op_Equality、 op_Inequality、 op_LessThan、 op_LessThanOrEqual、 op_GreaterThan、および op_GreaterThanOrEqual。

倉換挔算子は、末尟に「~」が付き、その埌に戻り倀型が続きたす。 倉換挔算子の゜ヌスたたは宛先のいずれかがゞェネリック型の堎合、「<」および「">」文字はそれぞれ「{」および「}」文字に眮き換えられたす。

䜿甚される倉換挔算子関数名の完党なセットは、 op_Explicit、 op_CheckedExplicit、および op_Implicitです。

namespace Acme
{
    class Widget : IProcess
    {
        public static explicit operator int(Widget x) { ... }
        public static implicit operator long(Widget x) { ... }
    }
}

ID:

"M:Acme.Widget.op_Explicit(Acme.Widget)~System.Int32"
"M:Acme.Widget.op_Implicit(Acme.Widget)~System.Int64"

D.5 䟋

D.5.1 C# ゜ヌス コヌド

次の䟋は、Point クラスの゜ヌス コヌドを瀺しおいたす。

namespace Graphics
{
    /// <summary>
    /// Class <c>Point</c> models a point in a two-dimensional plane.
    /// </summary>
    public class Point
    {
        /// <value>
        /// Property <c>X</c> represents the point's x-coordinate.
        /// </value>
        public int X { get; set; }
        
        /// <value>
        /// Property <c>Y</c> represents the point's y-coordinate.
        /// </value>
        public int Y { get; set; }
        
        /// <summary>
        /// This constructor initializes the new Point to (0,0).
        /// </summary>
        public Point() : this(0, 0) {}
        
        /// <summary>
        /// This constructor initializes the new Point to
        /// (<paramref name="xPosition"/>,<paramref name="yPosition"/>).
        /// </summary>
        /// <param name="xPosition">The new Point's x-coordinate.</param>
        /// <param name="yPosition">The new Point's y-coordinate.</param>
        public Point(int xPosition, int yPosition) 
        {
            X = xPosition;
            Y = yPosition;
        }
        
        /// <summary>
        /// This method changes the point's location to
        /// the given coordinates. <see cref="Translate"/>
        /// </summary>
        /// <param name="xPosition">The new x-coordinate.</param>
        /// <param name="yPosition">The new y-coordinate.</param>
        public void Move(int xPosition, int yPosition) 
        {
            X = xPosition;
            Y = yPosition;
        }
        
        /// <summary>
        /// This method changes the point's location by
        /// the given x- and y-offsets.
        /// <example>For example:
        /// <code>
        /// Point p = new Point(3, 5);
        /// p.Translate(-1, 3);
        /// </code>
        /// results in <c>p</c>'s having the value (2, 8).
        /// <see cref="Move"/>
        /// </example>
        /// </summary>
        /// <param name="dx">The relative x-offset.</param>
        /// <param name="dy">The relative y-offset.</param>
        public void Translate(int dx, int dy)
        {
            X += dx;
            Y += dy;
        }
        
        /// <summary>
        /// This method determines whether two Points have the same location.
        /// </summary>
        /// <param name="o">
        /// The object to be compared to the current object.
        /// </param>
        /// <returns>
        /// True if the Points have the same location and they have
        /// the exact same type; otherwise, false.
        /// </returns>
        /// <seealso cref="operator=="/>
        /// <seealso cref="operator!="/>
        public override bool Equals(object o)
        {
            if (o == null)
            {
                return false;
            }
            if ((object)this == o) 
            {
                return true;
            }
            if (GetType() == o.GetType()) 
            {
                Point p = (Point)o;
                return (X == p.X) && (Y == p.Y);
            }
            return false;
        }

        /// <summary>
        /// This method returns a Point's hashcode.
        /// </summary>
        /// <returns>
        /// The int hashcode.
        /// </returns>
        public override int GetHashCode()
        {
            return X + (Y >> 4);    // a crude version
        }
        
        /// <summary>Report a point's location as a string.</summary>
        /// <returns>
        /// A string representing a point's location, in the form (x,y),
        /// without any leading, training, or embedded whitespace.
        /// </returns>
        public override string ToString() => $"({X},{Y})";
        
        /// <summary>
        /// This operator determines whether two Points have the same location.
        /// </summary>
        /// <param name="p1">The first Point to be compared.</param>
        /// <param name="p2">The second Point to be compared.</param>
        /// <returns>
        /// True if the Points have the same location and they have
        /// the exact same type; otherwise, false.
        /// </returns>
        /// <seealso cref="Equals"/>
        /// <seealso cref="operator!="/>
        public static bool operator==(Point p1, Point p2)
        {
            if ((object)p1 == null || (object)p2 == null)
            {
                return false;
            }
            if (p1.GetType() == p2.GetType())
            {
                return (p1.X == p2.X) && (p1.Y == p2.Y);
            }
            return false;
        }
        
        /// <summary>
        /// This operator determines whether two Points have the same location.
        /// </summary>
        /// <param name="p1">The first Point to be compared.</param>
        /// <param name="p2">The second Point to be compared.</param>
        /// <returns>
        /// True if the Points do not have the same location and the
        /// exact same type; otherwise, false.
        /// </returns>
        /// <seealso cref="Equals"/>
        /// <seealso cref="operator=="/>
        public static bool operator!=(Point p1, Point p2) => !(p1 == p2);
    }
}

D.5.2 結果の XML

以䞋は、䞊蚘に瀺したクラス Point の゜ヌス コヌドを指定したずきに、あるドキュメント ゞェネレヌタによっお生成された出力です。

<?xml version="1.0"?>
<doc>
  <assembly>
    <name>Point</name>
  </assembly>
  <members>
    <member name="T:Graphics.Point">
    <summary>Class <c>Point</c> models a point in a two-dimensional
    plane.
    </summary>
    </member>
    <member name="M:Graphics.Point.#ctor">
      <summary>This constructor initializes the new Point to (0, 0).</summary>
    </member>
    <member name="M:Graphics.Point.#ctor(System.Int32,System.Int32)">
      <summary>
        This constructor initializes the new Point to
        (<paramref name="xPosition"/>,<paramref name="yPosition"/>).
      </summary>
      <param name="xPosition">The new Point's x-coordinate.</param>
      <param name="yPosition">The new Point's y-coordinate.</param>
    </member>
    <member name="M:Graphics.Point.Move(System.Int32,System.Int32)">
      <summary>
        This method changes the point's location to
        the given coordinates.
        <see cref="M:Graphics.Point.Translate(System.Int32,System.Int32)"/>
      </summary>
      <param name="xPosition">The new x-coordinate.</param>
      <param name="yPosition">The new y-coordinate.</param>
      </member>
    <member name="M:Graphics.Point.Translate(System.Int32,System.Int32)">
      <summary>
        This method changes the point's location by
        the given x- and y-offsets.
        <example>For example:
        <code>
        Point p = new Point(3,5);
        p.Translate(-1,3);
        </code>
        results in <c>p</c>'s having the value (2,8).
        </example>
        <see cref="M:Graphics.Point.Move(System.Int32,System.Int32)"/>
      </summary>
      <param name="dx">The relative x-offset.</param>
      <param name="dy">The relative y-offset.</param>
    </member>
    <member name="M:Graphics.Point.Equals(System.Object)">
      <summary>
        This method determines whether two Points have the same location.
      </summary>
      <param name="o">
        The object to be compared to the current object.
      </param>
      <returns>
        True if the Points have the same location and they have
        the exact same type; otherwise, false.
      </returns>
      <seealso 
        cref="M:Graphics.Point.op_Equality(Graphics.Point,Graphics.Point)" />
      <seealso 
        cref="M:Graphics.Point.op_Inequality(Graphics.Point,Graphics.Point)"/>
    </member>
     <member name="M:Graphics.Point.ToString">
      <summary>
        Report a point's location as a string.
      </summary>
      <returns>
        A string representing a point's location, in the form (x,y),
        without any leading, training, or embedded whitespace.
      </returns>
     </member>
    <member name="M:Graphics.Point.op_Equality(Graphics.Point,Graphics.Point)">
      <summary>
        This operator determines whether two Points have the same location.
      </summary>
      <param name="p1">The first Point to be compared.</param>
      <param name="p2">The second Point to be compared.</param>
      <returns>
        True if the Points have the same location and they have
        the exact same type; otherwise, false.
      </returns>
      <seealso cref="M:Graphics.Point.Equals(System.Object)"/>
      <seealso
        cref="M:Graphics.Point.op_Inequality(Graphics.Point,Graphics.Point)"/>
    </member>
    <member
        name="M:Graphics.Point.op_Inequality(Graphics.Point,Graphics.Point)">
      <summary>
        This operator determines whether two Points have the same location.
      </summary>
      <param name="p1">The first Point to be compared.</param>
      <param name="p2">The second Point to be compared.</param>
      <returns>
        True if the Points do not have the same location and the
        exact same type; otherwise, false.
      </returns>
      <seealso cref="M:Graphics.Point.Equals(System.Object)"/>
      <seealso
        cref="M:Graphics.Point.op_Equality(Graphics.Point,Graphics.Point)"/>
      </member>
      <member name="M:Graphics.Point.Main">
        <summary>
          This is the entry point of the Point class testing program.
          <para>
            This program tests each method and operator, and
            is intended to be run after any non-trivial maintenance has
            been performed on the Point class.
          </para>
        </summary>
      </member>
      <member name="P:Graphics.Point.X">
        <value>
          Property <c>X</c> represents the point's x-coordinate.
        </value>
      </member>
      <member name="P:Graphics.Point.Y">
        <value>
          Property <c>Y</c> represents the point's y-coordinate.
        </value>
    </member>
  </members>
</doc>

情報テキストの末尟。