3

I have a method which throws a generic exception and I would like to document it, however I cannot figure out how to write a valid xml doc.

        /// <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));
        }

The above gives the below error:

XML comment has a csref attribute that refers to a type parameter.

MaYaN
  • 6,683
  • 12
  • 57
  • 109
  • possible duplicate of [Referring to a generic type of a generic type in C# XML documentation?](http://stackoverflow.com/questions/684982/referring-to-a-generic-type-of-a-generic-type-in-c-sharp-xml-documentation) – Hugo Delsing Jan 20 '15 at 13:41
  • Thanks Hugo, but unfortunately that does not apply to this question. I have no problem documenting a method which say has an IList as an argument. The question asked here is specifically about generic exceptions. Please provide an example if you think the other question answers this one and I will close this question. – MaYaN Jan 20 '15 at 13:46
  • @MaYaN your question is very hard to understand, would you like to explain your problem a little bit more? – BendEg Jan 20 '15 at 14:10

1 Answers1

0

At the end I figured it out using:

/// <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));
}
MaYaN
  • 6,683
  • 12
  • 57
  • 109