XML comments style guidelines
See original GitHub issueIn CoreFX we didn’t call out a standard for XML comments. Since we have so much active cleanup and code generation I think we should develop some consistency guidelines, with the following goals:
Goals (in priority order)
- Code style is consistent
- Comments are readable
- Comments are maintainable
- Comments have real value
Here are some starting guidelines for discussion:
Guideline 1: Use XML style comments for methods and classes.
// DO
/// <summary>
/// Start the timer.
/// </summary>
public void Start() {}
// DO NOT
// Start the timer.
public void Start() {}
Guideline 2: Indent tag content by one extra space (two total) when on separate lines for readability.
// PREFER
/// <summary>
/// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
/// labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
/// laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
/// voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
/// non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
/// </summary>
// AVOID
/// <summary>
/// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
/// labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
/// laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
/// voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
/// non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
/// </summary>
Guideline 3: Avoid adding comments that simply repeat the name of the element.
// DO NOT
/// <summary>
/// MyClass class.
/// </summary>
public class MyClass {}
Guideline 4: Use <see cref="" /> and <paramref name="" /> blocks when refering to other code elements or URLs. This helps with code navigation and will keep comments up to date when refactoring.
// DO
/// <summary>
/// Opens a handle for the given <paramref name="device"/>.
/// Use <see cref="CloseHandle(IntPtr)" /> to close the handle
/// when no longer needed.
/// </summary>
public IntPtr OpenHandle(string device) {}
// DO NOT
/// <summary>
/// Opens a handle for the given device. Use CloseHandle()
/// to close the handle when no longer needed.
/// </summary>
public IntPtr OpenHandle(string device) {}
cc: @bartonjs
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:15 (15 by maintainers)
Top Results From Across the Web
Recommended XML tags for C# documentation comments
This article provides the syntax and definitions for recommended tags for XML documentation.
Read more >XML Document Format Style Guide
This document provides a set of guidelines for general use when designing new XML document formats (and to some extent XML documents as...
Read more >XML Comments: Using Them in XML and Other Languages
XML Comments Rules · You Can't Place a Comment Before the XML Declaration · You Can't Put a Comment Within Attribute Values ·...
Read more >Guidelines to Better XML Doc Comments and Documentation
Guidelines to Better XML Doc Comments and Documentation · 1. Don't hardcode true, false, null, Nothing, static and other language specific ...
Read more >XML Comments | Types and Examples of ...
Comments in XML is declared as: It has two sections starting and ending the comment. Have to be very clear that nesting comments...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

💡 If you want assistance in XML documentation syntax, consider adding DotNetAnalyzers.DocumentationAnalyzers to the project. It has a bunch of rules to help get things like paragraphs and lists correct, and even has a refactoring that allows a comment to initially be written as Markdown and then converted to XML syntax. More information about the specific rules can be found on its documentation page. If you have questions about any of the incomplete documentation pages please feel free to ask.
We’ve settled on the above as the current working set.