如何修改Solution/Project对象?
How to modify Solution/Project object?
我已经定义了属性 MyAttribute :应该在 class 中只使用一次的属性(每个 class 只有一个构造函数可能拥有它,并且它只能在 ctor 的属性列表中出现一次).
我创建了一个 Roslyn 分析器来检查它,它标记了此类属性的每次使用(如果多次使用)并允许用户选择名为 "Leave this attribute occurrence and delete all others" 的夹具。
现在在 FixProvider 中,我需要 return 新修改的解决方案。修改每个需要修复的文档并不难(通过使用 SyntaxRewriter 修改内部的 SyntaxTree)。但是,我不知道如何修改解决方案或项目 - 他们没有像 "ReplaceProject"/"ReplaceDocument".
这样的任何方法
怎么做?
您可以使用以下方法替换文档的文本:
solution = solution.WithDocumentText(currentDocument.Id,
currentDocumentSyntaxTree.GetText());
我已经定义了属性 MyAttribute :应该在 class 中只使用一次的属性(每个 class 只有一个构造函数可能拥有它,并且它只能在 ctor 的属性列表中出现一次).
我创建了一个 Roslyn 分析器来检查它,它标记了此类属性的每次使用(如果多次使用)并允许用户选择名为 "Leave this attribute occurrence and delete all others" 的夹具。
现在在 FixProvider 中,我需要 return 新修改的解决方案。修改每个需要修复的文档并不难(通过使用 SyntaxRewriter 修改内部的 SyntaxTree)。但是,我不知道如何修改解决方案或项目 - 他们没有像 "ReplaceProject"/"ReplaceDocument".
这样的任何方法怎么做?
您可以使用以下方法替换文档的文本:
solution = solution.WithDocumentText(currentDocument.Id,
currentDocumentSyntaxTree.GetText());