views:

151

answers:

1

Hello,

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!

+2  A: 

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.

Joel Coehoorn
Kent Boogaart
Thanks, good know.
Joel Coehoorn
thank you both for your replies! kent, using your link I've seen that your class is well documented. I guess you are generating some kidn of HTML from this? Which tool are you using for this task? Last time I looked for such tools they were all for earlier dot net versions or hard to use for beginners.I'll accept joels answer, first it's a short solution, second kent added his solution as comment which isn't markable, else I would mark it too ;-)
stefan.at.wpf
oh another question, any chance visual studio shows me directly that i made mistakes in the XML? currently I see the error only when hovering the documented method. A direct error like errors in code would be useful.
stefan.at.wpf
Don't forget you need to do the same for <, > and " (< > "). If you want to generate MSDN-like documentation in HTML, CHM or other formats, you can use free Sandcastle or our VSdocman. VSdocman contains also comment editor which automatically escapes all necessary characters.
Peter Macej
Kent Boogaart