private async Task<Document> ApplyAttribute(Document document, PropertyDeclarationSyntax propertyDeclaration, string attributeName, CancellationToken cancellationToken) { var attribute = SyntaxFactory.Attribute(SyntaxFactory.IdentifierName(attributeName)); var syntaxes = new[] { attribute }; var attributeList = propertyDeclaration.AttributeLists.Add(SyntaxFactory.AttributeList().WithAttributes(SyntaxFactory.SeparatedList(syntaxes)).WithTrailingTrivia(SyntaxFactory.SyntaxTrivia(SyntaxKind.EndOfLineTrivia, Environment.NewLine))); var syntaxNode = (await document.GetSyntaxRootAsync(cancellationToken)).ReplaceNode(propertyDeclaration, propertyDeclaration.WithAttributeLists(attributeList)); return document.WithSyntaxRoot(syntaxNode); }
private PropertyDeclarationSyntax RemoveAttribute(PropertyDeclarationSyntax node, string attributeName) { var changedAttributeLists = RemoveAttribute(attributeName, node.AttributeLists); var newProperty = node.WithAttributeLists(changedAttributeLists); return newProperty; }