Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio XML comments (summary) and special characters

I have a method in a C# / Wpf project and I'd like to comment / document it using the XML comments like this

    /// <summary>
    /// Initialises Drag & Drop
    /// </summary>
    void initDragDrop()
    {

    }

When I now use this method somewhere in my project and hover the mouse over it, I get the message "XML comment contains invalid XML: At this place, no spaces are allowed" (I translated the text after the colon manually to english, so it may not be literally in your visual studio). I found out the problem is the "&" sign, if I remove it, it works fine. But I want to keep it, so how to I escape it in the XML summary? I tried "\&" but this isn't working.

Thanks for any hint!

like image 260
stefan.at.wpf Avatar asked Apr 20 '10 16:04

stefan.at.wpf


1 Answers

Remember that the & character has special meaning in xml (the start of an entity). You need to write your comment like this instead (annoying, I know):

/// <summary>
/// Initialises Drag &amp; Drop
/// </summary>
void initDragDrop()
{

}

I might be wrong on this next point, but I don't think you can even use a CDATA section to avoid the entity, because it breaks the comments. You must type out the entire &amp; entity.

like image 86
Joel Coehoorn Avatar answered Oct 18 '22 08:10

Joel Coehoorn