XML documentation on generics

Hi,

I've been searching the MSDN docs, Googling around and trying to search these forums, but yet have to find an answer to my question.

How do you reference a generic class using XML documentation? Obviously, <see cref="System.Collections.Generic.List<T>"/> doesn't work. I tried <see cref="System.Collections.Generic.List`1"/> - as that is how MSIL treats it, but that didn't work either. What is the correct syntax for doing this?

Thanks in advance!

Frederik Carlier

[498 byte] By [FrederikCarlier] at [2008-2-13]
# 1

Yea I took a while to find this one as well.

Simply do the following <see cref="System.Collections.Generic.List&lt;T&gt;"/>.

DavidM.Kean at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 2
Cool, that did the trick!

Thanks

FrederikCarlier at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 3

That works, but it's very cumbersome to type. How about a helper in the IDE or in the C# compiler so that we can type foo<T> instead of foo&lt;T&;gt?

ChrisNahr at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 4

I agree.

However, I just found this: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=c274e29a-acc8-4507-b411-e73d322ce4aa

Apparently you can also use {} instead of the <> (for example: <see cref="IList{T}"/>), I haven't actually tried using it yet.

DavidM.Kean at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 5
Thanks for the link! Who would've thunk, the curly braces notation is actually a standard C# feature. Here's the relevant paragraph from the "Final Working Draft" (April 2005) for the C# 2.0 specs:

"For code elements that contain code that uses generics, the normal generics syntax, for instance List<T>, cannot be used because it produces invalid XML. Instead, curly braces can be used, such as <see cref=”List{T}”/>, or the normal XML escape syntax &lt; and &gt; for instance as in List&lt;T&gt;."

"Members of generic types are refered to as List{T}.Add(T). The variable T in Add(T) is bound by the type parameter T in List{T}. Similarly, the parameter type T of the generic method Sort{T}(T[]) is bound by the type-parameter T. In general, a generic method in a generic class is refered to as C{S}.F{T}(S, List{T}, U), here the parameter S is bound by the type parameter of the class C{S} and the T in List{T} is bound by the type parameter of the generic method F{T}, the parameter type U is free."

ChrisNahr at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...