feO2x
feO2x

Reputation: 5728

Is there any way to preserve white space in C# XML comments?

I'm currently documenting my C# code and would find it useful to include a code block that directly shows how a piece of code should be called. I use the <code> tag that is embedded into the summary:

Code block embedded in C# XML comment summary

While this works in general, I would like to preserve white space (line breaks, indentation). I tried the following so far:

Br tags work, but space and tab are ignored by the parser

Is there any way to preserve white space in code tags of C# XML comments? Thank you for your help in advance.

Upvotes: 12

Views: 4387

Answers (1)

Peter Macej
Peter Macej

Reputation: 5577

Your first XML doc comment is correct. You shouldn't rely on what Intellisense shows you in the tooltips. Intellisense doesn't respect all formatting but it's getting better with each release of VS.

The newlines and whitespaces in a <code> tag are respected by tools that generate documentation out of the XML comments, such as VSdocman (I am the author) or Sandcastle. The same applies to CDATA. So if you generate, for example, an HTML documentation from your comments, your code block will look fine, with all whitespaces and newlines.

If you want to see it correctly also in Intellisense, you have to wait, or even better, send a feedback from Visual Studio to the MS team.

Upvotes: 8

Related Questions