如何在C#中记录抛出泛型异常的方法?

3

我有一个会抛出通用异常的方法,我想对它进行文档记录,但是我不知道如何编写有效的xml文档。

        /// <summary>
        /// Throws any exception.
        /// </summary>
        /// <typeparam name="TException">Type of the exception to throw </typeparam>
        /// <exception cref="TException"> Thrown when whatever.... </exception>
        public static void Throw<TException>() where TException : Exception
        {
            throw (TException)Activator.CreateInstance(typeof(TException));
        }

上述代码会导致以下错误:
XML注释具有引用类型参数的csref属性。

可能是在C# XML文档中引用泛型类型的泛型类型?的重复问题。 - Hugo Delsing
谢谢Hugo,但不幸的是这并不适用于这个问题。我没有问题记录一个带有IList<string>参数的方法。这里提出的问题特别涉及通用异常。如果您认为其他问题回答了这个问题,请提供一个示例,我将关闭此问题。 - MaYaN
@MaYaN,您的问题很难理解,请问您能否再详细解释一下? - BendEg
1个回答

0

最后我使用以下方法解决了问题:

/// <summary>
/// Throws any exception.
/// </summary>
/// <typeparam name="TException">Type of the exception to throw </typeparam>
/// <exception>Thrown when
///     <cref>TException</cref> whatever...
/// </exception>    
public static void Throw<TException>() where TException : Exception
{
    throw (TException)Activator.CreateInstance(typeof(TException));
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接