Adding a C# documenation code example that contains a generic.

Topics: General Questions, Sandcastle
May 28, 2008 at 3:15 AM
Hi - I've got a code example for a class that uses generics. Here's the class declaration:


public class Schedule<T>: List<T> where T : ITask

And here is what the documentation comment looks like:



/// <summary>
/// Represents a generic collection of tasks.
/// </summary>
/// <example>
/// <code>
/// Schedule<ITask> taskSchedule = new Schedule<ITask>();
/// </code>
/// </example>

So you probably see the problem already. The <> of the declaration of the Schedule<> object thinks I'm nesting another custom tag but not closing it.

When I build the doc project, the example does not show up in the compiled help file. Any suggestions/work arounds?


May 28, 2008 at 4:53 AM

You have to escape those characters in XML.  For example:

/// <code>
/// Schedule &lt;ITask&gt; taskSchedule = new Schedule&lt;ITask&gt;();
/// </code>

As you can see, &lt; is the entity reference for less than and &gt; is the entity reference for greater than.

You can also escape ampersand characters with &amp; quotes with &quot; and apostrophes with &apos;

- Dave
May 28, 2008 at 6:45 AM
Excellent - thanks for the reminder!