question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

XML comments style guidelines

See original GitHub issue

In 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)

  1. Code style is consistent
  2. Comments are readable
  3. Comments are maintainable
  4. 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
sharwellcommented, Aug 9, 2019

💡 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.

0reactions
JeremyKuhnecommented, Aug 11, 2020

We’ve settled on the above as the current working set.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found