public void Can_change_attribute_name_and_output() { string csharpCode = @" [Foo(""Fred"", bar : 3, bar2 = 3.14, bar3=true)] public class Bar { public string FooBar() {} }"; IRoot root = RDom.CSharp.Load(csharpCode); IClass class1 = root.RootClasses.First(); IAttribute attribute1 = class1.Attributes.Attributes.First(); RDomAttribute attribute2 = class1.Attributes.Attributes.First().Copy() as RDomAttribute; Assert.IsTrue(attribute1.SameIntent(attribute2)); attribute2.Name = "Foo2"; Assert.IsFalse(attribute1.SameIntent(attribute2)); Assert.AreEqual("Foo2", attribute2.Name); string expected = " [Foo2(\"Fred\", bar : 3, bar2 = 3.14, bar3=true)] \r\n"; string actual = RDom.CSharp.GetSyntaxNode(attribute2).ToFullString(); SyntaxNode syntax1 = RDom.CSharp.GetSyntaxNode(class1); string actualClass = syntax1.ToFullString(); Assert.AreEqual(expected, actual); Assert.AreEqual(csharpCode, actualClass); }
private static IEnumerable <RDomAttribute> AttributesFromSyntax( RDomStructuredDocumentation parent, SemanticModel model, IEnumerable <XmlAttributeSyntax> attributes) { var list = new List <RDomAttribute>(); foreach (var attributeSyntax in attributes) { var valueNode = attributeSyntax .ChildNodes() .LastOrDefault(); var attribute = new RDomAttribute(attributeSyntax, parent, model); attribute.Name = attributeSyntax.Name.ToString(); var value = ""; if (valueNode != null) { value = valueNode.ToString(); var attributeValue = new RDomAttributeValue(attribute, "", value: value); attribute.AddOrMoveAttributeValue(attributeValue); } list.Add(attribute); } return(list); }