Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML multiline comments in C# - what am I doing wrong?

According to this article, it's possible to get multiline XML comments -- instead of using ///, use /** */. This is my interpretation of what multiline comments are, and what I want to have happen:

/**
 * <summary>
 * this comment is on line 1 in the tooltip
 * this comment is on line 2 in the tooltip
 * </summary>
 */

However, when I use this form, the tooltip that pops up when I hover over my class name in my code is single-line, i.e. it looks exactly as if I had written my comment like this:

/// <summary>
/// this comment is on line 1 in the tooltip
/// this comment is on line 2 in the tooltip
/// </summary>

Is this behavior actually possible still in VS2008?

EDIT

gabe pointed out that I have misunderstood what "multiline" means, and I actually need to use <para> or <br> to get my intended effect. I went ahead and used <br> because I want to control where the line breaks occur, i.e.

/// <summary>
/// this comment is on line 1 in the tooltip<br/>
/// this comment is on line 2 in the tooltip<br/>
/// </summary>

When I look at the tooltip for this class in my code, everything still ends up on one line... WTH? Did I do something wrong here?

UPDATE

Ok, I went ahead and tried the <para> tag on each line, and that works. Not sure why <br/> doesn't.

/// <summary>
/// <para>this comment is on line 1 in the tooltip</para>
/// <para>this comment is on line 2 in the tooltip</para>
/// </summary>
like image 529
Dave Avatar asked Mar 30 '10 17:03

Dave


People also ask

How do you comment multiple lines in XML?

If you are using Eclipse IDE you can comment out lines in an XML file by highlighting them and press Ctrl+Shift+c.

How do I comment in an XML file?

An XML comment encountered outside the document type declaration is represented by the Comment value syntax element. It contains the comment text from the XML message. If the value of the element contains the character sequence --> , the sequence is replaced with the text --&gt; .

How do I uncomment an XML file?

Shortcut key is Ctrl+shift+/. To uncomment in XML file, select the line/code which is commented and press Ctlr+shift+\. Its awesome!


3 Answers

Try this

/// <summary> /// this comment is on line 1 in the tooltip /// <para>this comment is on line 2 in the tooltip</para> /// </summary> 
like image 72
bic Avatar answered Oct 03 '22 19:10

bic


It sounds like you are confused about what "multi-line" means. A single-line comment ends at the end of the line of source code, and if you want to continue that comment you must put a "///" on the next line. A multi-line comment starts with a "/*" and ends with a "*/" so it can end either on the same line or multiple lines down.

Being "multi-line" says nothing about any how the text within the comment is displayed. To put a line break in an XML comment you must insert a <br/> ("break") or wrap the line in a <para> ("paragraph") tag.

like image 30
Gabe Avatar answered Oct 03 '22 17:10

Gabe


Add <br/> for line breaks or enclose the paragraphs in <para>...</para>. It's just like XML and HTML, the line break is nothing but whitespace.

like image 27
Lucero Avatar answered Oct 03 '22 17:10

Lucero