[ACCEPTED]-Referring to a generic type of a generic type in C# XML documentation?-xml-documentation
There seems to be no way to refer to a generic 13 of a generic in XML documentation, because 12 actually, there's no way to refer to a generic 11 of any specific type.
Lasse V Karlsen's answer made 10 it click for me:
If you write <see cref="IEnumerable{Int32}" />
, the compiler 9 just uses "Int32" as the type 8 parameter name, not the type argument. Writing 7 <see cref="IEnumerable{HelloWorld}" />
would work just as well. This makes sense 6 because there is no specific page in MSDN 5 for "IEnumerable of int" that 4 your documentation could link to.
To document 3 your class properly, I think you'd have 2 to write something like:
<summary>
Returns an <see cref="IEnumerable{T}" /> of <see cref="KeyValuePair{T,U}" />
of <see cref="String" />, <see cref="Int32" />.
</summary>
I hope you like 1 text.
What exactly would you like it to link to?
There's 8 no such thing in the documentation as a 7 Expression<Func<T>>
, so obviously a link to that would not 6 work.
You can link to Expression<TDelegate>
because that exists.
As 5 for what works or not, neither of the following 4 works in Visual Studio 2008 / .NET 3.5 for 3 me:
/// <see cref="Expression<Func<T>>"/>.
/// <see cref="Expression{Func{T}}"/>.
But this works:
/// <see cref="Expression{T}"/>.
so apparently the generic 2 type parameter doesn't have to the same 1 as the one in the declaration.
// Use "<" instead of "<" symbol and ">" instead of ">" symbol.
// Sample:
<see cref="Expression<Func<T, bool>>"/>
0
Don't use an empty see element (<see cref="..." />
). Instead, put 1 text inside the see element
<see cref="IEnumerable{T}">IEnumerable</see><<see cref="..."/>$gt;
I'm running into this now, as I have a function 7 that returns a List<List<byte>>
. Yeah, it's ugly, but I 6 didn't write it. Standard disclaimer, I 5 know.
Anyway, in VS 2017 with R# Ultimate 4 2017.1, this doc comment...
<returns><see cref="List{List{Byte}}" /> of split frames</returns>
...gives me a 3 syntax error. However, this...
<returns><see><cref>List{List{byte}}</cref></see> of split frames</returns>
...does not. Eeeenteresting.
Still 2 ugly? Yes.
As ugly? I think it's less horrible 1 than using <
and >
myself....
I tried everything on stack overflow to 4 a get results that work under several scenarios. Here's 3 a solution that works for me. (That's subjective 2 concerning anyone else.)
- Produces clickable links.
- Hovering over identifiers works.
- Produces .xml file correctly.
- Produces no errors in intellisense.
- Works for nullable generic type parameters.
- Works in Resharper and it's built-in XML Doc window (Resharper -> Edit -> Show Quick Documentation)
- Works in XAM Doc Preview for Atomineer Pro Documentaion Visual Studio Extension.
- Works with a generic type of a generic type.
Example #1
/// <summary>
/// This instance field holds a reference to the
/// <see cref="ConcurrentDictionary{Decimal, Boolean}"/> as
/// <see cref="T:ConcurrentDictionary<decimal, bool?>"/> that contains
/// the list of all PDF's that are currently opened and being displayed.
/// </summary>
private ConcurrentDictionary<decimal, bool?> openedPdfs = default!;
Note:
The ConcurrentDictionary{Decimal, Boolean} will correctly produce a
clickable link of ConcurrentDictionary{TKey, TValue} on hovering while
T:ConcurrentDictionary<decimal, bool?> makes sure the reader gets
information on what type TKey and TValue are.
Example 1 # 2 (using "T")
/// <summary>
/// This instance field holds a reference to the
/// <see cref="ConcurrentDictionary{TKey, TValue}"/> as
/// <see cref="T:ConcurrentDictionary<decimal, bool?>"/> that contains
/// the list of all PDF's that are currently opened and being displayed.
/// </summary>
private ConcurrentDictionary<decimal, bool?> openedPdfs = default!;
I came to use this:
<see cref=""EqualityComparer{T}.Default"">EqualityComparer<<typeparamref name=""TSource""/>>.Default</see>
Applied to your OP here 2 the result:
<see cref="System.Linq.Expressions.Expression{TDelegate}">Expression<Func<<typeparamref name="TSource"/>, Boolean>>.</see>
Here the image of the IntelliSense 1 pop-up:
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.