DO
- use the english language
- write full sentences beginning capitalized and ending with a period
- be precise
- use documentation comments (
///) where applicable - write comments in separate lines above the code they comment
- use a space between comment delimiters (
//,/*,*) and the comment
DO NOT
- use comments to remove parts of code
- leave outdated comments in the code
Documentation comments are formatted using XML tags. These are processed by the compiler, they can be exported into documentation files and shown in IntelliSense.
Documentation comments can be used on nearly everything except namespaces.
- The
summarytag should only display the most important information - Use
remarksto add additional information to the documentation - The comments rules from above apply as well
- Every type should have at least the
summarydocumentation summaryshould begin with the keywordsRepresentsorProvides
/// <summary>
/// Represents a mesh.
/// </summary>
public class Mesh { }
/// <summary>
/// Provides user input
/// </summary>
public class Input { }
- A method should atleast be documented with a
summarytag - Method
summaryalways begins with a verb - 'summary' documents what is done, not how
- If there are method parameter they should be documented with
param boolparameter descriptions begin withSpecifies wetherenumparameters should be documented withSpecifies ...
- A return value should be documented using the
returnstag - In case of
boolreturns the description should follow the concept oftrue if condition; else false
- An exception that needs catching should be documented
- Use the
exceptiontag with a reference to the type of an exception and state the reason why an exception occurred
/// <summary>
/// Writes the mesh to a file.
/// </summary>
/// <param name="path">The file system path</param>
/// <param name="overwriteExisting">Specifies whether an existing file will be overwritten</param>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null" />.</exception>
public void WriteMeshToFile(string path, bool overwriteExisting)
{
...
}
summarydocumentation starts withGets,SetsorGets or setsdepending on whether it is read-only, write-only or fully accessible
/// <summary>
/// Gets or sets the vertices.
/// </summary>
public Vertex[] Vertices { get; set; }