提交 1cb1bcb7 编写于 作者: C chborl

respond to feedback

上级 e83297d7
......@@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Options;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.ConvertAutoPropertyToFullProperty
{
......@@ -97,14 +98,18 @@ internal bool IsValidAutoProperty(SyntaxNode property, IPropertySymbol propertyS
propertySymbol.Type, fieldName,
initializer: GetInitializerValue(property));
//var containingType = GetTypeBlock(
// propertySymbol.ContainingType.DeclaringSyntaxReferences.FirstOrDefault().GetSyntax(cancellationToken));
var containingType = propertySymbol.ContainingType.DeclaringSyntaxReferences
.Select(r => GetTypeBlock(r.GetSyntax(cancellationToken)))
.Single(d => property.Ancestors().Contains(d));
editor.ReplaceNode(containingType, (currentTypeDecl, _)
=> CodeGenerator.AddFieldDeclaration(currentTypeDecl, newField, workspace)
.WithAdditionalAnnotations(Formatter.Annotation));
var typeDeclaration = propertySymbol.ContainingType.DeclaringSyntaxReferences;
foreach (var td in typeDeclaration)
{
var block = GetTypeBlock(await td.GetSyntaxAsync(cancellationToken).ConfigureAwait(false));
if (property.Ancestors().Contains(block))
{
editor.ReplaceNode(block, (currentTypeDecl, _)
=> CodeGenerator.AddFieldDeclaration(currentTypeDecl, newField, workspace)
.WithAdditionalAnnotations(Formatter.Annotation));
}
}
var newRoot = editor.GetChangedRoot();
return document.WithSyntaxRoot(newRoot);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册