public void GetAttributeAttributesTest() { FieldElement fieldElement = new FieldElement(); fieldElement.Name = "TestField"; string attribute = ElementUtilities.GetAttribute(ElementAttributeType.Attributes, fieldElement); Assert.AreEqual(string.Empty, attribute, "Unexpected attribute."); // // Add some attributes to the element. // AttributeElement attribute1 = new AttributeElement(); attribute1.Name = "Attribute1"; attribute1.BodyText = "false"; AttributeElement attribute2 = new AttributeElement(); attribute2.Name = "Attribute2"; attribute2.BodyText = "false"; fieldElement.AddAttribute(attribute1); fieldElement.AddAttribute(attribute2); attribute = ElementUtilities.GetAttribute(ElementAttributeType.Attributes, fieldElement); Assert.AreEqual("Attribute1, Attribute2", attribute, "Unexpected attribute."); // // Add nested attributes to the element. // fieldElement.ClearAttributes(); attribute1 = new AttributeElement(); attribute1.Name = "Attribute1"; attribute1.BodyText = "false"; attribute2 = new AttributeElement(); attribute2.Name = "Attribute2"; attribute2.BodyText = "false"; attribute1.AddChild(attribute2); fieldElement.AddAttribute(attribute1); attribute = ElementUtilities.GetAttribute(ElementAttributeType.Attributes, fieldElement); Assert.AreEqual("Attribute1, Attribute2", attribute, "Unexpected attribute."); }
/// <summary> /// Parses an attribute. /// </summary> /// <param name="comments">The comments.</param> /// <param name="nested">Whether or not the attribute is nested/chained.</param> /// <returns>An attribute code element.</returns> private AttributeElement ParseAttribute(ReadOnlyCollection<ICommentElement> comments, bool nested) { AttributeElement attributeElement = new AttributeElement(); string typeName = CaptureTypeName(false); EatLineContinuation(); // // Check for an attribute target // if (TryReadChar(VBSymbol.LineDelimiter)) { attributeElement.Target = typeName; typeName = CaptureTypeName(false); EatLineContinuation(); } attributeElement.Name = typeName; if (NextChar == VBSymbol.BeginParameterList) { string attributeText = ParseNestedText( VBSymbol.BeginParameterList, VBSymbol.EndParameterList, true, true); attributeElement.BodyText = attributeText; } EatLineContinuation(); while (!nested && TryReadChar(VBSymbol.AliasSeparator)) { if (NextChar != VBSymbol.AliasSeparator) { AttributeElement childAttributeElement = ParseAttribute(null, true); if (string.IsNullOrEmpty(childAttributeElement.Target)) { childAttributeElement.Target = attributeElement.Target; } attributeElement.AddChild(childAttributeElement); } } EatLineContinuation(); if (!nested) { EatChar(VBSymbol.EndAttribute); } if (comments != null && comments.Count > 0) { foreach (ICommentElement comment in comments) { attributeElement.AddHeaderComment(comment); } } return attributeElement; }