XML Documentation – What to Include in Comments

ccoding-style

I'm trying to make a point of documenting my code better, especially when it comes to the XML comments on class members, but often it just feels silly.

In the case of event handlers, the naming convention and parameters are standard and clear:

/// <summary>
/// Handler for myCollection's CollectionChanged Event.
/// </summary>
/// <param name="sender">Event Sender</param>
/// <param name="e">Event Arguments</param>
private void myCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    // actual code here...
}

I also frequently have simple properties that are (IMO) named clearly so that the summary is redundant:

/// <summary>
/// Indicates if an item is selected.
/// </summary>
public bool ItemIsSelected
{ get { return (SelectedItem != null); } }

I don't feel like such comments don't add any information that the declaration itself doesn't already convey. The general wisdom seems to be that a comment that repeats the code is best left unwritten.

Obviously, XML documentation is more than just regular inline code comments, and ideally will have 100% coverage. What should I be writing in such cases? If these examples are OK, what value do they add that I may not be appreciating now?

Best Answer

XML doc comments are intended for public members.

The compiler warning clearly states this:

Missing XML comment for publicly visible type or member 'Type_or_Member'

You should only add XML comments to private members if those members aren't already obvious from their names.

Related Topic