private static PropertyDeclarationSyntax AddAttribute(PropertyDeclarationSyntax property, string attributeName) { var newAttributes = SyntaxFactory.AttributeList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Attribute(SyntaxFactory.IdentifierName(attributeName)) ) ); property = property.AddAttributeLists(newAttributes); return property; }
private PropertyDeclarationSyntax EnsureAttribute(PropertyDeclarationSyntax property, AttributeSyntax attributeSyntax) { var attributeName = GetSimpleNameFromNode(attributeSyntax).Identifier.ValueText; if (HasAttribute(property.AttributeLists, attributeName)) { property = RemoveAttribute(property, attributeName); } var newAttributes = SyntaxFactory.AttributeList( SyntaxFactory.SingletonSeparatedList(attributeSyntax) ); property = property.AddAttributeLists(newAttributes); return property; }