I am trying to include a code snippet in my class XML documentation but the compiler complaining that an xml element is not closed! Here 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 to replace the code snippet by /// <c> MyClass class = new MyClass{String}(); </c>
Any one has experienced this before?
Thanks for your help
Using this, the programmer will improve the performance of an application. In addition to performance, generics provide type-safety and higher quality code because you get to reuse data processing algorithms without duplicating type-specific code. Generics are also known as Parametric polymorphism.
In a nutshell, generics enable types (classes and interfaces) to be parameters when defining classes, interfaces and methods. Much like the more familiar formal parameters used in method declarations, type parameters provide a way for you to re-use the same code with different inputs.
In xml documentation, you have 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 forced to do this, it because it genuinely isn't well formed xml if you allow triangular braces outside of element markup.
The replace you tried is correct.
You didn't close the Remarks
element in the 4th line, it might be complaining about that, just at the wrong line number.
Also, with examples containing generics, it picks up List<string>
as the text literal List
followed by an unclosed string
XML element. The easiest way around this is to do List &lt;string&gr;
which when parsed produces List<string>
without being an XML element.
The C# compiler team added {
and }
as replacements for that, so you can just do List{string}
and it will be processed into <>'s.
A couple of things:
<
and >
characters by replacing them with <
and >
.<remarks>
section with a </remarks>
<see ... />
, <seealso ... />
, etc.) then you would do so like the following: <see cref="SomeMethod{T}(T value)" />
. Never specify a concrete type in the reference (that is, don't do <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<string<();</c></para>
/// </note>
/// </remarks>
public class MyClass<T>
{
....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With