Search code examples
c#documentation

Xml string in a C# summary comment


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?


Solution

  • 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.