public override SyntaxNode VisitAttributeList(AttributeListSyntax attributeList) { var nodesToRemove = attributeList.Attributes.Where(att => s_ShouldRemoveAttributeApplication(att.Name.ToString())).ToArray(); if (nodesToRemove.Length == attributeList.Attributes.Count) { //Remove the entire attribute return(attributeList.RemoveNode(attributeList, SyntaxRemoveOptions.KeepNoTrivia)); } else { //Remove just the matching ones recursively foreach (var node in nodesToRemove) { return(VisitAttributeList(attributeList.RemoveNode(node, SyntaxRemoveOptions.KeepNoTrivia))); } } return (base.VisitAttributeList(attributeList)); }
public override SyntaxNode VisitAttributeList(AttributeListSyntax node) { var propAttribute = node.Attributes.FirstOrDefault(a => a.Name.NormalizeWhitespace().ToFullString().Equals(_attributeName)); if (propAttribute != null) { if (node.Parent is PropertyDeclarationSyntax || node.Parent is ClassDeclarationSyntax) { if (node.Attributes.Count == 1) { return(null); } return(node.RemoveNode(propAttribute, SyntaxRemoveOptions.KeepNoTrivia)); } } return(base.VisitAttributeList(node)); }
public override SyntaxNode VisitAttributeList(AttributeListSyntax node) { var testFixture = node.Attributes .SingleOrDefault(attribute => attribute.IsTestFixtureAttribute()); // no test fixture, this isn't an NUnit class if (testFixture == null) { return(base.VisitAttributeList(node)); } _options.RequiresXUnitImport = true; // only one attribute in the list (e.g. [TestFixture] ), remove the entire list. if (node.Attributes.Count == 1) { return(null); } // multiple attributes in a list (e.g. [TestFixture, DataContract] ), remove only the TestFixture attribute. var newList = node.RemoveNode(testFixture, SyntaxRemoveOptions.KeepNoTrivia); return(base.VisitAttributeList(newList)); }
public static AttributeListSyntax Convert(AttributeListSyntax node, RequiredUsings requires) { var testFixture = node.Attributes .SingleOrDefault(attribute => attribute.IsTestFixtureAttribute()); // no test fixture, this isn't an NUnit class if (testFixture == null) { return(node); } requires.XUnit = true; // only one attribute in the list (e.g. [TestFixture] ), remove the entire list. if (node.Attributes.Count == 1) { return(NullAttributeList(node)); } // multiple attributes in a list (e.g. [TestFixture, DataContract] ), remove only the TestFixture attribute. var newList = node.RemoveNode(testFixture, SyntaxRemoveOptions.KeepExteriorTrivia); return(newList); }