2011-06-22 26 views
8

下面是一个例子:XML评论 - 如何评论异常的多种原因?

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

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

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

或其他方式?

/// <exception cref="ArgumentNullException"> 
///  Some other way to show the 2 reasons with an "-or-" between them. 
/// </exception> 

回答

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> 

您可以使用“P”元素来表示线条。

+2

我真的结束了使用,但它似乎应该有一个更好的方式来做到这一点。好吧。此外,应使用而不是

。他们都是平等的,但考虑到智能识别,我认为这是首选。 –

+0

我认为加倍“”与将文档中的表行加倍相同。当然,'para'标签要好得多。 –