src/Misc/EFTools/EntityDesign/VisualStudio/VsUtils.cs
// <summary>
//     Helper to find first child element with a particular attribute with
//     a particular value (if any attribute value is good use null, but
//     note this is different from an empty string which will require the
//     attribute to have an empty value).
//     If such a child element doesn't exist, create it.
// </summary>
Helper to find first child element with a particular attribute with
a particular value (if any attribute value is good use null, but
note this is different from an empty string which will require the
attribute to have an empty value).
If such a child element doesn't exist, create it.
Helper to find first child element with a particular attribute with a particular value ( if any attribute value is good use null but note this is different from an empty string which will require the attribute to have an empty value ) . If such a child element doesn ' t exist create it .
private static XmlElement FindOrCreateChildXmlElementWithAttribute(
            XmlNode parentNode, string elementName, string attributeName, string attributeValue, IComparer<string> comparer)
        {
            var xmlNodeList = parentNode.SelectNodes(elementName);
            if (null != xmlNodeList)
            {
                foreach (XmlNode xmlNode in xmlNodeList)
                {
                    var attribute = xmlNode.Attributes[attributeName];
                    if (null != attribute)
                    {
                        var elem = xmlNode as XmlElement;
                        if (null == attributeValue)
                        {
                            return elem;
                        }
                        else
                        {
                            if (comparer != null
                                && comparer.Compare(attributeValue, attribute.Value) == 0)
                            {
                                elem.SetAttribute(attributeName, attributeValue);
                                return elem;
                            }
                            else if (attribute.Value == attributeValue)
                            {
                                return elem;
                            }
                        }
                    }
                }
            }
            var xmlElement = parentNode.OwnerDocument.CreateElement(elementName);
            xmlElement.SetAttribute(attributeName, attributeValue);
            parentNode.AppendChild(xmlElement);
            return xmlElement;
        }
private static XmlElement FindOrCreateChildXmlElementWithAttribute ( XmlNode parentNode , string elementName , string attributeName , string attributeValue , IComparer < string > comparer ) { var xmlNodeList = parentNode . SelectNodes ( elementName ) ; if ( null != xmlNodeList ) { foreach ( XmlNode xmlNode in xmlNodeList ) { var attribute = xmlNode . Attributes [ attributeName ] ; if ( null != attribute ) { var elem = xmlNode as XmlElement ; if ( null == attributeValue ) { return elem ; } else { if ( comparer != null && comparer . Compare ( attributeValue , attribute . Value ) == 0 ) { elem . SetAttribute ( attributeName , attributeValue ) ; return elem ; } else if ( attribute . Value == attributeValue ) { return elem ; } } } } } var xmlElement = parentNode . OwnerDocument . CreateElement ( elementName ) ; xmlElement . SetAttribute ( attributeName , attributeValue ) ; parentNode . AppendChild ( xmlElement ) ; return xmlElement ; }
Helper to find first child element with a particular attribute with
a particular value (if any attribute value is good use null, but
note this is different from an empty string which will require the
attribute to have an empty value).
Helper to find first child element with a particular attribute with a particular value ( if any attribute value is good use null but note this is different from an empty string which will require the attribute to have an empty value ) .
// if attribute value doesn't matter // if customComparer is passed, use it to compare the attribute value // else just do normal string comparison // otherwise element doesn't exist, so create it
parentNode
XmlNode
elementName
string
attributeName
string
attributeValue
string
comparer
IComparer<string>