Generics in XML documentation documentation

I am trying to include a code snippet in the XML class documentation, but the compiler complains that the xml element is not closed! This is what i am trying to achieve

/// <summary>
/// Method documentation here...
/// </summary>
/// <remarks>
/// <para>
/// This class should be used as follow:
/// <br/>
/// ************** PROBLEM IN NEXT LINE ********************
/// <c> MyClass class = new MyClass<String>(); </c>
/// </para>
/// </remarks>
public class MyClass<T>{
....
}

I tried replacing the code snippet with /// <c> MyClass class = new MyClass{String}(); </c>

Has anyone experienced this before?

thanks for the help

+5
source share
4 answers

In the xml documentation, you need to replace the triangular braces with curly braces:

 /// <summary>
 /// Calls <see cref="DoSomething{T}"/>.
 /// </summary>
 public void CallsDoSomething()
 {

 }

 public void DoSomething<T>()
 {

 }

The reason you end up having to do this is because it's really not well-formed xml if you allow triangular braces outside of the element layout.

The correct replacement.

+7
source

Remarks 4- , , .

, , , List<string> List, string XML. List &amp;lt;string&amp;gr;, List<string>, XML.

# { } , List{string}, < > 's.

+5

:

  • < >, &lt; &gt;.
  • XML <remarks> </remarks>
  • When you have decided to refer to the common text in the tag (ie <see ... />, <seealso ... />etc.), you must do the following: <see cref="SomeMethod{T}(T value)" />. Never specify a specific type in a link (i.e. do not <see cref="SomeMethod{String}(String value)" />).

Here is a fixed version of your XML comments:

/// <summary>
/// Method documentation here...
/// </summary>
/// <remarks>
/// <note type="implementsinfo">
///     <para>This class should be used as follow:</para>
///     <para><c>MyClass class = new MyClass&lt;string&lt;();</c></para>
/// </note>
/// </remarks>
public class MyClass<T>
{
    ....
}
+3
source

Your <remarks>never closes.

It also requires replacing angular brackets, as you have already tried.

+2
source

All Articles