Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

constructed generic type in cref part of xml-comment

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" />
like image 745
Snowbear Avatar asked Dec 06 '11 16:12

Snowbear


1 Answers

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.

like image 179
David Nelson Avatar answered Nov 06 '22 04:11

David Nelson