简体   繁体   中英

How to read XML documentation comments using Roslyn / Code Analysis

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.

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 ie as it would look in the original source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM