views:

319

answers:

1

I'm writing an HTML parser in C# and want to include examples of the HTML that it handles in the summary XML blocks. How do I prevent the < and > characters from messing up the auto-documentation of Visual Studio 2008?

example:

  /// <summary>
  /// Creates a FlowSegment based on an HTML code, i.e. <bold>
  /// </summary>
  /// <param name="code"></param>
  /// <returns></returns>
  public FlowSegment(string code)
  {

Unfortunately the example causes the tool tip for this constructor to display (in part):

XML comment includes invalid XML

instead of the summary comment.

How can I escape the < and > characters?

+12  A: 

The best solution I found was to change it so as to replace < with &lt; and > with &gt;

as found in the XML specifications.

That makes the example look as follows:

  /// <summary>
  /// Creates a FlowSegment based on an HTML code, i.e. &lt;bold&gt;
  /// </summary>
  /// <param name="code"></param>
  /// <returns></returns>
  public FlowSegment(string code)
  {

Which makes the desired tool-tip display properly.

Fred