You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Explain `///` comments without elements
Fixes#44161
Yes, roslyn interprets these comments and exports them to the XML file. However, the text isn't in a child XML element, and won't be interpreted by other tools.
* build warning
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/xmldoc/index.md
+12-10Lines changed: 12 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Documentation comments - document APIs using /// comments"
3
3
description: Learn about documentation comments. You can create documentation for your code by including XML elements in special comment fields. You can use other tools to build documentation layouts from comments.
4
-
ms.date: 06/14/2023
4
+
ms.date: 02/19/2025
5
5
f1_keywords:
6
6
- "cs.xml"
7
7
helpviewer_keywords:
@@ -11,12 +11,11 @@ helpviewer_keywords:
11
11
- "C# source code files"
12
12
- "C# language, XML code comments"
13
13
- "XML documentation comments [C#]"
14
-
ms.assetid: 803b7f7b-7428-4725-b5db-9a6cff273199
15
14
---
16
15
17
16
# Documentation comments
18
17
19
-
C# source files can have structured comments that produce API documentation for the types defined in those files. The C# compiler produces an *XML* file that contains structured data representing the comments and the API signatures. Other tools can process that XML output to create human-readable documentation in the form of web pages or PDF files, for example.
18
+
C# source files can include structured comments that produce API documentation for the types defined in those files. The C# compiler produces an *XML* file that contains structured data representing the comments and the API signatures. Other tools can process that XML output to create human-readable documentation in the form of web pages or PDF files, for example.
20
19
21
20
This process provides many advantages for you to add API documentation in your code:
22
21
@@ -26,7 +25,7 @@ This process provides many advantages for you to add API documentation in your c
26
25
27
26
Tools like Visual Studio provide IntelliSense for many common XML elements used in documentation comments.
28
27
29
-
This article covers these topics:
28
+
This article covers these articles:
30
29
31
30
- Documentation comments and XML file generation
32
31
- Tags validated by the C# compiler and Visual Studio
@@ -49,14 +48,14 @@ You set either the [**GenerateDocumentationFile**](../../../core/project-sdk/msb
49
48
50
49
The use of XML doc comments requires delimiters that indicate where a documentation comment begins and ends. You use the following delimiters with the XML documentation tags:
51
50
52
-
-`///` Single-line delimiter: The documentation examples and C# project templates use this form. If there's white space following the delimiter, it isn't included in the XML output.
51
+
-`///` Single-line delimiter: The documentation examples and C# project templates use this form. If white space follows the delimiter, it isn't included in the XML output.
53
52
> [!NOTE]
54
53
> Visual Studio automatically inserts the `<summary>` and `</summary>` tags and positions your cursor within these tags after you type the `///` delimiter in the code editor. You can turn this feature on or off in the [Options dialog box](/visualstudio/ide/reference/options-text-editor-csharp-advanced).
55
54
-`/** */` Multiline delimiters: The `/** */` delimiters have the following formatting rules:
56
55
- On the line that contains the `/**` delimiter, if the rest of the line is white space, the line isn't processed for comments. If the first character after the `/**` delimiter is white space, that white-space character is ignored and the rest of the line is processed. Otherwise, the entire text of the line after the `/**` delimiter is processed as part of the comment.
57
56
- On the line that contains the `*/` delimiter, if there's only white space up to the `*/` delimiter, that line is ignored. Otherwise, the text on the line up to the `*/` delimiter is processed as part of the comment.
58
57
- For the lines after the one that begins with the `/**` delimiter, the compiler looks for a common pattern at the beginning of each line. The pattern can consist of optional white space and/or an asterisk (`*`), followed by more optional white space. If the compiler finds a common pattern at the beginning of each line that doesn't begin with the `/**` delimiter or end with the `*/` delimiter, it ignores that pattern for each line.
59
-
- The only part of the following comment that's processed is the line that begins with `<summary>`. The three tag formats produce the same comments.
58
+
- The only part of the following comment processed is the line that begins with `<summary>`. The three tag formats produce the same comments.
60
59
61
60
```csharp
62
61
/** <summary>text</summary> */
@@ -100,10 +99,10 @@ The use of XML doc comments requires delimiters that indicate where a documentat
100
99
```
101
100
<!-- markdownlint-enable MD010 -->
102
101
103
-
To refer to XML elements (forexample, yourfunctionprocessesspecificXMLelementsthatyouwanttodescribeinanXMLdocumentationcomment), youcanusethestandardquotingmechanism (`<` and `>`). Torefertogenericidentifiersincodereference (`cref`) elements, youcanuseeithertheescapecharacters (forexample, `cref="List<T>"`) orbraces (`cref="List{T}"`).Asaspecialcase, thecompilerparsesthebracesasanglebracketstomakethedocumentationcommentlesscumbersometotheauthorwhenreferringtogenericidentifiers.
102
+
To refer to XML elements (forexample, yourfunctionprocessesspecificXMLelementsthatyouwanttodescribeinanXMLdocumentationcomment), youcanusethestandardquotingmechanism (`<` and `>`). Torefertogenericidentifiersincodereference (`cref`) elements, youcanuseeithertheescapecharacters (forexample, `cref="List<T>"`) orbraces (`cref="List{T}"`). Asaspecialcase, thecompilerparsesthebracesasanglebracketstomakethedocumentationcommentlesscumbersometotheauthorwhenreferringtogenericidentifiers.
>IfyouwritecommentsusingthesinglelineXMLcommentdelimiter, `///`, but don't include any tags, the compiler adds the text of those comments to the XML output file. However, the output doesn't include XML elements such as `<summary>`. Most tools that consume XML comments (including Visual Studio intellisense) don't read these comments.
107
106
108
107
## ToolsthatacceptXMLdocumentationinput
109
108
@@ -113,6 +112,9 @@ The following tools create output from XML comments:
113
112
- [Sandcastle](https://github.com/EWSoftware/SHFB): The *Sandcastle tools* create help files for managed class libraries containing both conceptual and API reference pages. The Sandcastle tools are command-line based and have no GUI front-end, project management features, or automated build process. The Sandcastle Help File Builder provides standalone GUI and command-line-based tools to build a help file in an automated fashion. A Visual Studio integration package is also available for it so that help projects can be created and managed entirely from within Visual Studio.
114
113
- [Doxygen](https://github.com/doxygen/doxygen): *Doxygen* generates an online documentation browser (in HTML) or an offline reference manual (in LaTeX) from a set of documented source files. There's also support for generating output in RTF (MS Word), PostScript, hyperlinked PDF, compressed HTML, DocBook, and Unix manual pages. You can configure Doxygen to extract the code structure from undocumented source files.
115
114
115
+
> [!NOTE]
116
+
> TheXMLdocumentationcommentsaren'tmetadata; theyaren't included in the compiled assembly and therefore they aren'taccessiblethroughreflection.
@@ -132,15 +134,15 @@ The compiler observes the following rules when it generates the ID strings:
132
134
| `E` |event||
133
135
| `!` |errorstring|Therestofthestringprovidesinformationabouttheerror. TheC# compilergenerateserrorinformationforlinksthatcan't be resolved. |
134
136
135
-
-Thesecondpartofthestringisthefullyqualifiednameoftheitem, startingattherootofthenamespace. Thenameoftheitem, itsenclosingtype(s), andnamespaceareseparatedbyperiods. Ifthenameoftheitemitselfhasperiods, they're replaced with the hash-sign ('#'). It'sassumedthatnoitemhasahash-signdirectlyinitsname. Forexample, thefullyqualifiednameoftheStringconstructoris"System.String.#ctor".
137
+
-Thesecondpartofthestringisthefullyqualifiednameoftheitem, startingattherootofthenamespace. Thenameoftheitem, itsenclosingtype(s), andnamespaceareseparatedbyperiods. Ifthenameoftheitemitselfhasperiods, they're replaced with the hash-sign ('#'). The grammar assumes that no item has a hash-sign directly in its name. For example, the fully qualified name of the String constructor is "System.String.#ctor".
136
138
-Forpropertiesandmethods, theparameterlistenclosedinparenthesesfollows. Iftherearenoparameters, noparenthesesarepresent. Theparametersareseparatedbycommas. Theencodingofeachparameterfollowsdirectlyhowit's encoded in a .NET signature (See <xref:Microsoft.VisualStudio.CorDebugInterop.CorElementType?displayProperty=fullName> for definitions of the all caps elements in the following list):
137
139
-Basetypes. Regulartypes (`ELEMENT_TYPE_CLASS` or `ELEMENT_TYPE_VALUETYPE`) arerepresentedasthefullyqualifiednameofthetype.
138
140
-Intrinsictypes (forexample, `ELEMENT_TYPE_I4`, `ELEMENT_TYPE_OBJECT`, `ELEMENT_TYPE_STRING`, `ELEMENT_TYPE_TYPEDBYREF`, and `ELEMENT_TYPE_VOID`) arerepresentedasthefullyqualifiednameofthecorrespondingfulltype. Forexample, `System.Int32` or `System.TypedReference`.
- `ELEMENT_TYPE_ARRAY` isrepresentedas [*lowerbound*:`size`,*lowerbound*:`size`] wherethenumberofcommasistherank - 1, andthelowerboundsandsizeofeachdimension, ifknown, arerepresentedindecimal. Thelowerboundandsizeareomittediftheyaren't specified. If the lower bound and size for a particular dimension is omitted, the ':' is omitted as well. For example, a two-dimensional array with 1 as the lower bounds and unspecified sizes is [1:,1:].
144
146
-Forconversionoperatorsonly (`op_Implicit` and `op_Explicit`), thereturnvalueofthemethodisencodedasa `~` followedbythereturntype. Forexample:
- For generic types, the name of the type is followed by a backtick and then a number that indicates the number of generic type parameters. For example:
0 commit comments