4

I would like to retrieve the XML documentation of elements (like classes, properties) from my C# code using Roslyn. However, the only relevant method I found is GetDocumentationCommentXml, which just gives me the whole XML, but not the parsed elements.

In another SO post someone asked the same question and got an answer. But that question is 3 years old and the API changed: The suggested GetDocumentationComment method does not exist anymore.

Community
  • 1
  • 1
  • You should check the source code of the StyleCopAnalyzers. They do extensive use of Roslyn to analyze XML comments. Here: [source code on GitHub](https://github.com/DotNetAnalyzers/StyleCopAnalyzers). – Hugo Quintela Ribeiro May 11 '16 at 09:18
  • They seem to manually parse the XML themselves, which seems very weird. Isn't the point of Roslyn that you can leverage the same parsing and tooling than the compiler and Visual Studio? – Froco Hudri May 11 '16 at 09:27
  • 4
    File a feature request on GitHub to make http://source.roslyn.io/#Microsoft.CodeAnalysis.Workspaces/Shared/Utilities/DocumentationComment.cs public. – SLaks May 11 '16 at 14:01
  • I've done something quite similar for my internship last year and I had to manually parse comments in order to find common syntactical errors in comments. It's not a feature available in Roslyn now if I'm correct. – Kevin Avignon May 18 '16 at 13:20

1 Answers1

0

The method you are probably looking for is ISymbol.GetDocumentationCommentXml. This returns a comment in .xml doc format, which is slightly different to the raw comments in the code.

Unfortunately the GetDocumenationComment is now part of an internal class, which itself uses DocumentationComment.FromXmlFragment to convert the XML back to a code comment i.e. as it would look in the original source.

Jack Ukleja
  • 13,061
  • 11
  • 72
  • 113