[ACCEPTED]-Referring to a generic type of a generic type in C# XML documentation?-xml-documentation

Accepted answer
Score: 48

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.

Score: 12

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&lt;Func&lt;T&gt;&gt;"/>.
/// <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.

Score: 3
// Use "&lt;" instead of "<" symbol and "&gt;" instead of ">" symbol.

// Sample:

<see cref="Expression&lt;Func&lt;T, bool&gt;&gt;"/>

0

Score: 2

Don't use an empty see element (<see cref="..." />). Instead, put 1 text inside the see element

<see cref="IEnumerable{T}">IEnumerable</see>&lt;<see cref="..."/>$gt;
Score: 1

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 &lt; and &gt; myself....

Score: 0

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.)

  1. Produces clickable links.
  2. Hovering over identifiers works.
  3. Produces .xml file correctly.
  4. Produces no errors in intellisense.
  5. Works for nullable generic type parameters.
  6. Works in Resharper and it's built-in XML Doc window (Resharper -> Edit -> Show Quick Documentation)
  7. Works in XAM Doc Preview for Atomineer Pro Documentaion Visual Studio Extension.
  8. 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&lt;decimal, bool?&gt;"/> 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&lt;decimal, bool?&gt; 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&lt;decimal, bool?&gt;"/> that contains
  ///  the list of all PDF's that are currently opened and being displayed.
  /// </summary>
  private ConcurrentDictionary<decimal, bool?> openedPdfs = default!;
Score: 0

I came to use this:

<see cref=""EqualityComparer{T}.Default"">EqualityComparer&lt;<typeparamref name=""TSource""/>&gt;.Default</see>

Applied to your OP here 2 the result:

<see cref="System.Linq.Expressions.Expression{TDelegate}">Expression&lt;Func&lt;<typeparamref name="TSource"/>, Boolean&gt;&gt;.</see>

Here the image of the IntelliSense 1 pop-up:

Render of the comment in VS2019

More Related questions