public void SetAttributes(INamedNodeMap nodemap) { foreach (IAttr atr in nodemap) { TagAttributes.Add(atr.Name, atr.Value); } }
/// <summary> /// Compares another attribute container to the current container. /// </summary> /// <param name="sourceAttributes">The original attribute list.</param> /// <param name="targetAttributes">The list to compare to.</param> /// <returns>True if both objects are equal, otherwise false.</returns> public static Boolean SameAs(this INamedNodeMap sourceAttributes, INamedNodeMap targetAttributes) { if (sourceAttributes.Length == targetAttributes.Length) { foreach (var elA in sourceAttributes) { var found = false; foreach (var elB in targetAttributes) { found = elA.GetHashCode() == elB.GetHashCode(); if (found) { break; } } if (!found) { return(false); } } return(true); } return(false); }
private bool AttributesAreEqual(INamedNodeMap attributeMapX, INamedNodeMap attributeMapY) { if (_options.IgnoreAdditionalAttributes) { if (attributeMapX.Length > attributeMapY.Length) { return(false); } } else if (attributeMapX.Length != attributeMapY.Length) { return(false); } foreach (var attributeX in attributeMapX) { // Id & Class are handled separately if (attributeX.Name == ClassAttributeName || attributeX.Name == IdAttributeName) { continue; } var attributeY = attributeMapY.GetNamedItem(attributeX.NamespaceUri, attributeX.Name); if (attributeY == null || !_options.AttributeComparer.Equals(attributeX.Value, attributeY.Value)) { return(false); } } return(true); }
/// <summary> /// Compares another attribute container to the current container. /// </summary> /// <param name="sourceAttributes">The original attribute list.</param> /// <param name="targetAttributes">The list to compare to.</param> /// <returns>True if both objects are equal, otherwise false.</returns> public static Boolean AreEqual(this INamedNodeMap sourceAttributes, INamedNodeMap targetAttributes) { if (sourceAttributes.Length == targetAttributes.Length) { foreach (var elA in sourceAttributes) { var found = false; foreach (var elB in targetAttributes) { found = elA.GetHashCode() == elB.GetHashCode(); if (found) break; } if (!found) { return false; } } return true; } return false; }
public async Task BeClosedByDefault() { // Arrange IRenderedComponent <BfTreeView> cut = RenderComponent <BfTreeView>( p => p.AddChildContent <BfTreeItem>() ); // Assert INamedNodeMap attrs = cut.Find(BfComponentApis.BfTreeItem.Html.BfTreeItem).Attributes; attrs.GetNamedItem(BfComponentApis.BfTreeItem.Attributes.Expanded) .Should().BeNull(); }
public async Task BeOpenWhenConfiguredSo() { // Arrange IRenderedComponent <BfTreeView> cut = RenderComponent <BfTreeView>( p => p.AddChildContent <BfTreeItem>( pa => { pa.Add(b => b.Expanded, true); }) ); // Assert INamedNodeMap attrs = cut.Find(BfComponentApis.BfTreeItem.Html.BfTreeItem).Attributes; attrs.GetNamedItem(BfComponentApis.BfTreeItem.Attributes.Expanded) .Should().NotBeNull(); }
/// <summary> /// Clears the given attribute collection. /// </summary> /// <param name="attributes">The collection to clear.</param> /// <returns>The collection itself.</returns> public static INamedNodeMap Clear(this INamedNodeMap attributes) { if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); } while (attributes.Length > 0) { var name = attributes[attributes.Length - 1].Name; attributes.RemoveNamedItem(name); } return(attributes); }
/// <summary>Searches for children that have the given name and attribute</summary> protected internal static INode GetChildByNameAndAttribute(INode node, string name, string attributeName, string attributeValue) { INodeList children = node.GetChildNodes(); INamedNodeMap attribs = node.GetAttributes(); INode attribute = null; // this node matches if (node.GetNodeName().Equals(name) && attribs != null && (attribute = attribs.GetNamedItem(attributeName)) != null && attribute.GetNodeValue().Equals(attributeValue)) { return(node); } // search children for (int i = 0; i < children.GetLength(); i++) { INode found = GetChildByAttribute(children.Item(i), attributeName, attributeValue); if (found != null) { return(found); } } // failed return(null); }