The constructed generic type in the cref part of xml-comment

I have a generic exception class, for example:

public class DuplicateException<TEntity> : Exception { public TEntity Entity { get; set; } } 

And I have a non-generic method that can throw a generic exception thrown:

 void Save() { throw new DuplicateException<SomeEntity>(); } 

This method can throw this general exception, but only from this constructed type DuplicateException<SomeEntity> , and it cannot pass this exception with any other type parameter instead of SomeEntity .

Now I want to indicate this fact in xml-comment for the Save method. This article describes a little how to comment on methods with a general exception, and I tried these two alternatives:

1) Inserts default autocomplete in VS:

 /// <exception cref="DuplicateException{TEntity}" /> 

2) Replaced TEntity with SomeEntity

 /// <exception cref="DuplicateException{SomeEntity}" /> 

But in both cases, the output XML still claims that this method can invoke a generic unconstructed type that SomeEntity does not mention at SomeEntity :

 <exception cref="T:MyNameSpace.DuplicateException`1" /> 
+6
source share
1 answer

The purpose of the cref attribute is to link to the documentation for the type. But there is no documentation on specific type types, so it is not surprising that the generated cref attribute is intended to define a generic type. Your concern is that you want to display something else that is in the link. You can do this by using an element, because the content of the element is link text. But in the element, the content of the element is a description of when the exception occurs. Therefore, I do not think that there is a way to do what you are looking for.

+3
source

Source: https://habr.com/ru/post/903210/


All Articles