Skip to content

Commit 71aeda8

Browse files
Youssef1313Sergio0694
authored andcommitted
Fix failing test
1 parent 450fb9f commit 71aeda8

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/CommunityToolkit.Mvvm.CodeFixers/UsePartialPropertyForSemiAutoPropertyCodeFixer.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,11 @@ private static async Task<Document> ConvertToPartialProperty(Document document,
9898
// Find the parent type for the property
9999
TypeDeclarationSyntax typeDeclaration = propertyDeclaration.FirstAncestorOrSelf<TypeDeclarationSyntax>()!;
100100

101-
// Make sure it's partial
101+
// Make sure it's partial (we create the updated node in the function to preserve the updated property declaration).
102+
// If we created it separately and replaced it, the whole tree would also be replaced, and we'd lose the new property.
102103
if (!typeDeclaration.Modifiers.Any(SyntaxKind.PartialKeyword))
103104
{
104-
TypeDeclarationSyntax updatedTypeDeclaration = typeDeclaration.AddModifiers(Token(SyntaxKind.PartialKeyword));
105-
106-
editor.ReplaceNode(typeDeclaration, updatedTypeDeclaration);
105+
editor.ReplaceNode(typeDeclaration, static (node, generator) => generator.WithModifiers(node, generator.GetModifiers(node).WithPartial(true)));
107106
}
108107

109108
return document.WithSyntaxRoot(editor.GetChangedRoot());

0 commit comments

Comments
 (0)