Skip to content

Commit 6f4e0de

Browse files
committed
chore(template): sync with dailydevops/template-dotnet [skip ci]
1 parent dc5b6e7 commit 6f4e0de

1 file changed

Lines changed: 131 additions & 0 deletions

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
agent: 'agent'
3+
tools: ['changes', 'search/codebase', 'edit/editFiles', 'problems']
4+
description: 'Ensure that C# types are documented with XML comments following Microsoft documentation standards and project guidelines.'
5+
---
6+
7+
# C# Documentation Best Practices
8+
9+
## General Principles
10+
11+
* MUST document all public members with XML comments to ensure comprehensive API documentation.
12+
* SHOULD document internal members, especially those that are complex or implement non-obvious behavior.
13+
* MUST use English exclusively for all documentation comments (per project language standard).
14+
* MUST follow the C# 13 and modern language conventions when creating code examples within documentation.
15+
* MUST ensure documentation comments are concise, clear, and professional in tone.
16+
17+
## XML Documentation Tags
18+
19+
### Core Documentation Tags
20+
21+
* MUST use `<summary>` to provide a brief, one-line description of what the type or member does. Start the summary with a present-tense, third-person verb.
22+
* MUST use `<remarks>` for additional information, which can include implementation details, usage notes, platform-specific behavior, or other relevant context.
23+
* MUST use `<see langword>` for language-specific keywords like `null`, `true`, `false`, `int`, `bool`, and other C# language keywords.
24+
* MUST use `<c>` for inline code snippets and identifiers within text.
25+
* SHOULD use `<example>` to provide usage examples demonstrating how to use the member.
26+
* MUST place `<code>` blocks within `<example>` tags and add the `language="csharp"` attribute to enable proper syntax highlighting.
27+
* SHOULD include brief explanatory comments in code examples to clarify context or intent.
28+
* MUST use `<see cref>` to reference other types or members inline (within sentences) for cross-referencing.
29+
* MUST use `<seealso>` for standalone references to related types or members in the "See also" section of generated documentation.
30+
* MUST prefer `<see cref>`/`<seealso cref>` for internal references; MUST use `<see href="https://...">` or `<seealso href="https://...">` only for external URLs.
31+
* MUST use `https` URLs and include concise link text; MUST NOT emit raw `<a href>` tags in XML documentation.
32+
* SHOULD use `<inheritdoc />` to inherit documentation from base classes or interfaces when the behavior is identical.
33+
* MUST document behavior differences explicitly if significant changes exist from the base implementation.
34+
35+
## Type Documentation
36+
37+
* MUST document the purpose and responsibility of each public class, struct, interface, delegate, and enum.
38+
* MUST include usage examples for complex types that require specific initialization patterns.
39+
* SHOULD mention any platform-specific requirements or constraints.
40+
* SHOULD reference related types using `<seealso>` tags.
41+
42+
## Method Documentation
43+
44+
* MUST use `<param>` to describe each method parameter:
45+
* MUST phrase parameter descriptions as noun phrases without specifying the data type.
46+
* MUST begin descriptions with an appropriate introductory article (a, an, the, or none for countable items).
47+
* For flag enum parameters, MUST start with: "A bitwise combination of the enumeration values that specifies..."
48+
* For non-flag enum parameters, MUST start with: "One of the enumeration values that specifies..."
49+
* For Boolean parameters, MUST use the form: "`<see langword="true" />` to ...; otherwise, `<see langword="false" />`."
50+
* For "out" parameters, MUST use the form: "When this method returns, contains .... This parameter is treated as uninitialized."
51+
* MUST use `<paramref>` to reference parameter names when mentioned in documentation text.
52+
* MUST use `<typeparam>` to describe type parameters in generic types and generic methods.
53+
* MUST use `<typeparamref>` to reference type parameters when mentioned in documentation text.
54+
* MUST use `<returns>` to describe the return value:
55+
* MUST phrase return descriptions as noun phrases without specifying the data type.
56+
* MUST begin descriptions with an appropriate introductory article.
57+
* For Boolean return types, MUST use the form: "`<see langword="true" />` if ...; otherwise, `<see langword="false" />`."
58+
* For null return values, MUST clarify when `null` can be returned and under what conditions.
59+
* SHOULD use `<exception cref>` to document exceptions thrown directly by the method.
60+
* MUST only document exceptions that callers can reasonably handle.
61+
* MUST omit "Thrown if..." or "If..." prefixes; state the condition directly, for example: "An error occurred when accessing a required resource."
62+
63+
## Constructor Documentation
64+
65+
* MUST use the summary format: "Initializes a new instance of the `<ClassName>` class" or "struct" as appropriate.
66+
* SHOULD include information about initial state, default values, or invariants established during construction.
67+
* MUST document all constructor parameters using `<param>` tags.
68+
* SHOULD document constructor exceptions if applicable.
69+
70+
## Property Documentation
71+
72+
* MUST use `<summary>` starting with appropriate verb phrases based on property access:
73+
* "Gets or sets..." for read-write properties.
74+
* "Gets..." for read-only properties.
75+
* "Gets or sets a value that indicates whether..." for Boolean properties.
76+
* MUST use `<value>` to describe the property's value:
77+
* MUST phrase value descriptions as noun phrases without specifying the data type.
78+
* If the property has a default value, MUST include it in a separate sentence: "The default is `<see langword="false" />`."
79+
* For Boolean properties, MUST use the form: "`<see langword="true" />` if ...; otherwise, `<see langword="false" />`. The default is ..."
80+
* SHOULD document property exceptions if the getter or setter can throw exceptions.
81+
82+
## Field Documentation
83+
84+
* MUST document public fields with `<summary>` and `<remarks>` tags where appropriate.
85+
* SHOULD document constant fields to clarify their purpose and usage.
86+
* MUST use `<value>` to describe the field's content.
87+
88+
## Event Documentation
89+
90+
* MUST use `<summary>` to describe when the event is raised.
91+
* MUST use `<remarks>` to provide context about the event's behavior and typical usage patterns.
92+
* SHOULD document the event arguments using `<param>` tags if using custom EventArgs.
93+
94+
## Exception Documentation
95+
96+
* MUST use `<exception cref>` to document exceptions thrown by constructors, properties, indexers, methods, operators, and events.
97+
* MUST document all exceptions thrown directly by the member that callers can meaningfully handle.
98+
* For exceptions thrown by nested or indirect calls, SHOULD only document the exceptions users are most likely to encounter.
99+
* MUST phrase exception descriptions to describe the condition that triggers the exception:
100+
* Omit conditional prefixes; state the condition directly.
101+
* Example: "A required parameter is `null`." instead of "Thrown if a required parameter is null."
102+
103+
## Generic Types and Methods
104+
105+
* MUST use `<typeparam>` to document type parameters in generic types and methods:
106+
* MUST describe the constraints and purpose of each type parameter.
107+
* SHOULD clarify any performance or memory implications of type parameter choices.
108+
* MUST use `<typeparamref>` to reference type parameters in other documentation text.
109+
110+
## Code Examples in Documentation
111+
112+
* MUST use valid, compilable C# 13 code in examples.
113+
* SHOULD follow project coding conventions in examples (including null-checking with `is null`, modern patterns, switch expressions, etc.).
114+
* SHOULD include complete, runnable examples rather than fragments when the example is non-trivial.
115+
* MUST include explanatory comments for complex logic, but MUST NOT use "Act", "Arrange", or "Assert" labels in documentation examples.
116+
* SHOULD demonstrate both common and edge-case usage patterns.
117+
118+
## Special Considerations
119+
120+
* MUST apply nullable reference type annotations (`?`) to all public API documentation.
121+
* MUST use `NotNullAttribute` and related nullable attributes in public API documentation when appropriate.
122+
* MUST use `nameof()` operator in examples instead of string literals when referring to member names.
123+
* MUST ensure that documentation examples properly demonstrate null-checking patterns using `is null` and `is not null`.
124+
* SHOULD reference related decisions or architectural guidelines when relevant to the API's design or usage.
125+
126+
## Accessibility and Localization
127+
128+
* MUST ensure all documentation is written in clear, professional English suitable for a global audience.
129+
* SHOULD avoid idioms, colloquialisms, and culturally specific references.
130+
* MUST use simple, direct language while maintaining technical precision.
131+
* SHOULD define technical terms on first usage or reference external documentation.

0 commit comments

Comments
 (0)