如何在 C# 代码生成器中阅读 XML 文档?
我编写了一个简单的 C# 代码生成器,它实现了 Microsoft.CodeAnalysis.ISourceGenerator
,它检查 enum
声明并根据用某些属性修饰的成员生成代码。它按预期工作,只是我无法在我注册的 ISyntaxContextReceiver 中检索任何 XML 文档注释。
我已经尝试过这篇文章中找到的解决方案,但是我是否检查枚举常量语法模型的主要琐事或在枚举常量的语义模型上调用 GetDocumentationCommentXml()
时,永远不会有任何 XML 文档。 (前一种技术总是生成一个带有单个 WhitespaceTrivia
项的琐事集合;后者总是返回一个空字符串。)
我怀疑这是因为 GeneratorExecutionContext
传递给生成器的Execute 方法将 ParseOptions.DocumentationMode
设置为 DocumentationMode.None
,但我找不到任何方法来更改 ParseOptions
。有谁知道如何做到这一点或者还有什么可以实现 XML 文档节点的检索?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论