views:

1106

answers:

2

I'm documenting a few methods I wrote in C# that deal with parsing tokens. Due to some technical restraints in other areas of the system, these tokens need to take the form of XML elements (i.e., <tokenName />). I'd like to put the format of those tokens in the summary statement itself.

However, this throws an error: Badly formed XML -- A name was started with an invalid character". Is there any sort of escape character sequence I can use to embed XML in my C# summary comments?

+5  A: 

Yes. Use standard XML escaping. For example:

<summary>This takes a &lt;token1&gt; and turns it into a &lt;token2&gt;</summary>

It's not super-easy to type or read as code, but Intellisense properly unescapes this and you see the right, readable thing in the tooltip.

Andrew Arnott
Beaten to it by 10 seconds :)
Jon Skeet
@Andrew Arnott: Either that or a CDATA section.
casperOne
<gasp>Jon Skeet is mortal!</gasp>
Joel Coehoorn
+5  A: 

You need to use a CDATA section, like this:

<![CDATA[ your xml here ]]>

Example:

<![CDATA[ <name>Bob</name> ]]>
Sean
If the token has a CDATA section itself you cannot embend it into a CDATA section. This requires escaping
crauscher