Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Comments - How to comment multiple reasons for an exception?

Here's an example:

public void DoSomething(String param1, String param2)
{
    if (param1 == null) throw new ArgumentNullException("param1");
    if (param2 == null) throw new ArgumentNullException("param2");
}

2 different reasons for an ArgumentNullException. MSDNs String.Format Example shows 2 different reasons for the FormatException. So, is it done this way:

/// <exception cref="ArgumentNullException">
///     <paramref name="param1"/> is null.
/// </exception>
/// <exception cref="ArgumentNullException">
///     <paramref name="param2"/> is null.
/// </exception>

or some other way?

/// <exception cref="ArgumentNullException">
///     Some other way to show the 2 reasons with an "-or-" between them.
/// </exception>
like image 685
myermian Avatar asked Jun 22 '11 03:06

myermian


People also ask

Can XML comments be nested?

XML comment sections cannot be nested, because content cannot contain the value "-->".

Which is the proper commenting method for XML?

To insert XML comments for a code element Do one of the following: Type /// in C#, or ''' in Visual Basic.

What is cref c#?

The cref attribute in an XML documentation tag means "code reference." It specifies that the inner text of the tag is a code element, such as a type, method, or property.


1 Answers

If you think each of the rows of the docs as being one <exception cref=...> </exception>, then logically the correct way to do it is using your second alternative:

/// <exception cref="ArgumentNullException">
///     <p><paramref name="param1"/> is null. </p>
///     <p>- or - </p>
///     <p><paramref name="param2"/> is null. </p>
/// </exception>

You can use 'p' elements to denote the lines.

like image 141
Miguel Angelo Avatar answered Sep 19 '22 11:09

Miguel Angelo