I have generic exception class like this:
public class DuplicateException<TEntity> : Exception
{
public TEntity Entity { get; set; }
}
And I have non-generic method which might throw constructed generic exception:
void Save()
{
throw new DuplicateException<SomeEntity>();
}
This method may throw this generic exception but only of this one constructed type DuplicateException<SomeEntity>
and it cannot throw this exception with some other type parameter instead of SomeEntity
.
Now I want to specify this fact in xml-comment for Save
method. This article describes a little bit how to comment methods with generic exception and I've tried these two alternatives:
1) Inserts by defauly by autocomplete in VS:
/// <exception cref="DuplicateException{TEntity}" />
2) Replaced TEntity
with SomeEntity
/// <exception cref="DuplicateException{SomeEntity}" />
But in both cases output XML still states that this method might throw generic non-constructed type which doesn't mention SomeEntity
at all:
<exception cref="T:MyNameSpace.DuplicateException`1" />
The purpose of the cref attribute is to link to the documentation for a type. But there is no documentation for concrete generic types, so it's not surprising that the generated cref attribute is for the generic type definition. Your concern is that you want to display something different that what is in the link. You can do that when using the element, because the content of the element is the text of the link. But in the element, the content of the element is the description of when the exception occurs. So I don't think there is a way to do what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With