2

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?

Rich Armstrong
  • 143
  • 1
  • 7
  • Can you give a full minimal reproducible example please? – Andrew McClement Mar 14 '22 at 18:59
  • 2
    The generator consumer should have `true` property in csproj. This controls whether the compiler parses the documentation comments or not. – Youssef13 Mar 18 '22 at 12:26
  • @Youssef13: Thanks; that worked! But not without side effects: The (new) presence of the documentation file (.xml) could be ignored easily enough, but I had to disable no fewer than eight warning-message codes to suppress the hundreds of documentation warnings that appeared. I fear that I know the answer, but I'll ask anyway: Is there no other way to enable parsing of the documentation comments? – Rich Armstrong Mar 22 '22 at 15:40
  • I don't think there is. You should also take a more careful look to the warnings you disabled. Most of the time the warnings indicate an issue. – Youssef13 Mar 22 '22 at 19:33

0 Answers0