NewLine in object summary

C#NewlineSummary

C# Problem Overview


Greetings

When setting a summary for a property / field / method etc.. is it possible to have a newline in it?

/// <summary>
/// This is line 1
/// This is line 2
/// </summary>
public bool TestLine { get; set; }

When I set this it shows as on mouse over:

> bool TestLine > This is line 1 This is line 2

But I want it to show as:

> bool TestLine > This is line 1 > This is line 2

I've tried using \n but that doesn't work. Is there any way to get this done?

C# Solutions


Solution 1 - C#

You want to use some thing like this

/// <summary> 
/// Your Main comment 
/// <para>This is line 1</para> 
/// <para>This is line 2</para> 
/// </summary> 
public bool TestLine { get; set; }

Solution 2 - C#

This may be an old thread but I was searching for an anwser while using Visual Studio 2019. I wanted paragraph and lines breaks. The following works well for me:

/// <summary>
/// <para>parameter name="guidType" options:</para>
/// <br>0 = SequentialAsString</br>
/// <br>1 = SequentialAsBinary</br>
/// <br>2 = SequentialAtEnd</br>
/// </summary>

Produces the following:

parameter name="guidType" options:

0 = SequentialAsString
1 = SequentialAsBinary
2 = SequentialAtEnd

Solution 3 - C#

Yes:

/// <summary> 
/// Main comment 
/// <para>Line 1</para> 
/// <para>Line 2</para> 
/// </summary> 
public bool TestLine { get; set; }

Solution 4 - C#

You can use <para /> to add a new line within summary:

/// <summary> 
/// Main comment<para />
/// Line 1<para />
/// Line 2<para />
/// </summary>
public bool TestLine { get; set; }

Looks like:

Main comment
Line 1
Line 2

Best regards!

Solution 5 - C#

You can legitimately add para tags, but this actually creates a new paragraph for each new line and the line spacing appears off.
I personally add 1 para around the paragraph and then br tags at the end of the lines I wanted a break on, which preserves decent line spacing:

/// <summary> 
/// <para>Main comment<br /> 
/// Line 1<br />
/// Line 2</para> 
/// </summary>
public bool TestLine { get; set; }

Solution 6 - C#

I would suggest using this formatting if you want multiple lines in the summary without making it complicated. It'll work if you use the <br /> tag after each line. (using it anywhere inside the text will make a new line where the tag is also.)

Although, note that if you have a space after the <br /> tag, you would get an extra space one the next line. So you wanna have the same amount of space on each line, so every row it'll be in a straight line.

/// <summary>
/// This is line 1<br />
/// This is line 2<br />
/// This is line 3<br />
/// </summary>
public bool TestLine { get; set; }

Solution 7 - C#

I'm just adding this for anyone using Xamarin Studio like I am. I found that none of the above solutions work for me, but this one did:

/// <summary>
/// Main summarry line.
/// <para></para>
/// <para></para>
/// Your secondary summary
/// </summary>

This gives the following output:

Summary  
Main summary line.

Your secondary summary

Solution 8 - C#

If you are using Swashbuckle (Swagger Web API integration library) then <para></para> should be replaced with <p></p> and <br/> also could be used.

so the following

    /// <para>
    ///     Flag1, Flag2
    ///     - bool flags, optional.
    /// </para>

becomes

    /// <p>
    ///     Flag1, Flag2<br/>
    ///     - bool flags, optional.
    /// </p>

The issue is already described here: https://stackoverflow.com/questions/32559028/how-to-add-line-break-to-swashbuckle-documentation - using a special config, domaindrivendev's comment, https://github.com/domaindrivendev/Swashbuckle/issues/258 - on <br/> usage.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTheun ArbeiderView Question on Stackoverflow
Solution 1 - C#YetAnotherUserView Answer on Stackoverflow
Solution 2 - C#Thomas CayneView Answer on Stackoverflow
Solution 3 - C#Mitch WheatView Answer on Stackoverflow
Solution 4 - C#fdelgadoView Answer on Stackoverflow
Solution 5 - C#PDizzleView Answer on Stackoverflow
Solution 6 - C#JonathanView Answer on Stackoverflow
Solution 7 - C#head in the codesView Answer on Stackoverflow
Solution 8 - C#Dmitry KarpenkoView Answer on Stackoverflow