'How can I read XML documentation in a C# code generator?

I've written a simple C# code generator that implements Microsoft.CodeAnalysis.ISourceGenerator that inspects an enum declaration and generates code based on members that are decorated with certain attributes. It is working as expected except that I cannot retrieve—in the ISyntaxContextReceiver that I register—any XML documentation comments.

I've tried the solution found in this SO post, but whether I inspect the leading trivia on the enum constant's syntax model or call GetDocumentationCommentXml() on the enum constant's semantic model, there's never any XML documentation. (The former technique always yields a trivia collection with a single WhitespaceTrivia item; the latter always returns an empty string.)

I suspect that this is because the GeneratorExecutionContext passed to the generator's Execute method has ParseOptions.DocumentationMode set to DocumentationMode.None, but I can't find any way to change ParseOptions. Does anyone know how this can be done or what else might enable retrieval of XML documentation nodes?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source