Possible issue with ParseLeadingTrivia

Topics: APIs
Jul 21, 2014 at 9:14 PM
CTP 0.7.4052301 running in VS 2013

I have this code
        var triviaList = SyntaxFactory.ParseLeadingTrivia(newDocAsString);
with the following in the immediate window after execution
  • it does recognize this as a comment
  • it does not create a comment that can be output
    • the type is SyntaxTrivia, not DocumentationCommentTriviaSyntax
    • the initial three slashes has been stripped
My goal is simply to recreate XML documentation from the XDocument created from the string retrieved from the Symbol via GetDocumentationCommentXml (after changing it).

Doing this manually (like a sane variation of Roslyn Quoter output) has been quite difficult. I'd be happy to do this either the way I am attempting it or with helper methods if they are available. Any other thoughts also welcome

newDocAsString , nq
/// <summary>This is a test</summary>
/// <param name="dummy">With a dummy parameter</param>

triviaList.First().ToString() ,nq
<summary>This is a test</summary>
/// <param name="dummy">With a dummy parameter</param>

triviaList.First().CSharpKind()
SingleLineDocumentationCommentTrivia
Developer
Jul 26, 2014 at 3:30 PM
Try triviaList.ToFullString()

This is an artifact of doc comments being structured trivia. When then doc comment parses it treats the slashes '///' and leading whitespace as separate "sub" trivia, so the ToString/ToFullString rule applies with leading and trailing trivia. This would probably make sense if you were referencing the structured trivia node for the doc comment directly. But it does seems counterintuitive when referencing it as a piece of trivia itself.
Jul 27, 2014 at 12:18 PM
That's fine.