public override SyntaxNode VisitEnumDeclaration(EnumDeclarationSyntax node) { var newAttributes = SortAttributes(node.AttributeLists); if (newAttributes != node.AttributeLists) { node = node.WithAttributeLists(newAttributes); } return(base.VisitEnumDeclaration(node)); }
/// <summary> /// Add the attribute list to the <see cref="EnumDeclarationSyntax"/>. /// </summary> /// <param name="member">The <see cref="EnumDeclarationSyntax"/>.</param> /// <param name="attributeList">The <see cref="AttributeListSyntax"/>.</param> /// <returns>The <paramref name="member"/> with <paramref name="attributeList"/> added.</returns> public static EnumDeclarationSyntax WithAttributeList(this EnumDeclarationSyntax member, AttributeListSyntax attributeList) { if (member is null) { throw new System.ArgumentNullException(nameof(member)); } if (attributeList is null) { throw new System.ArgumentNullException(nameof(attributeList)); } return(member.WithAttributeLists(member.AttributeLists.Add(attributeList))); }
public override SyntaxNode VisitEnumDeclaration(EnumDeclarationSyntax node) { if (node.AttributeLists.Count > 0) { var newAttributeLists = new SyntaxList <AttributeListSyntax>(); foreach (var attributeList in node.AttributeLists) { var nodesToRemove = attributeList.Attributes.Where(attribute => NodeHelper.AttributeNameMatches(attribute, Constants.Proto.BASE_PROP_NAME)).ToArray(); // If the lists are the same length, we are removing all attributes and can just avoid populating newAttributes. if (nodesToRemove.Length != attributeList.Attributes.Count) { var newAttribute = (AttributeListSyntax)VisitAttributeList(attributeList.RemoveNodes(nodesToRemove, SyntaxRemoveOptions.KeepNoTrivia)); newAttributeLists = newAttributeLists.Add(newAttribute); } } var leadTriv = node.GetLeadingTrivia(); node = node.WithAttributeLists(newAttributeLists); node = node.WithLeadingTrivia(leadTriv); } return(base.VisitEnumDeclaration(node)); }