XML注释 - 如何评论异常的多个原因?

m-y*_*m-y 8 exception xml-comments

这是一个例子:

public void DoSomething(String param1, String param2)
{
    if (param1 == null) throw new ArgumentNullException("param1");
    if (param2 == null) throw new ArgumentNullException("param2");
}
Run Code Online (Sandbox Code Playgroud)

ArgumentNullException的2个不同原因.MSDNs String.Format示例显示了2个不同的原因FormatException.那么,它是这样做的:

/// <exception cref="ArgumentNullException">
///     <paramref name="param1"/> is null.
/// </exception>
/// <exception cref="ArgumentNullException">
///     <paramref name="param2"/> is null.
/// </exception>
Run Code Online (Sandbox Code Playgroud)

还是其他一些方式?

/// <exception cref="ArgumentNullException">
///     Some other way to show the 2 reasons with an "-or-" between them.
/// </exception>
Run Code Online (Sandbox Code Playgroud)

Mig*_*elo 14

如果您认为文档的每一行都是一个<exception cref=...> </exception>,那么逻辑上正确的方法就是使用您的第二个替代方案:

/// <exception cref="ArgumentNullException">
///     <p><paramref name="param1"/> is null. </p>
///     <p>- or - </p>
///     <p><paramref name="param2"/> is null. </p>
/// </exception>
Run Code Online (Sandbox Code Playgroud)

您可以使用'p'元素来表示线条.

  • 我实际上最终使用了它,但似乎应该有更好的方法来做到这一点.那好吧.此外,应使用<para> </ para>代替<p> </ p>.他们是平等的,但考虑到<para>被intellisense认可,我认为这是首选. (2认同)