src/Misc/EFTools/EntityDesign/VisualStudio/VsUtils.cs
// <summary>
//     Helper to finds or create all nodes specified in elementPath
// </summary>
// <param name="parentNode"></param>
// <param name="elementPath">full path to element separated by '/'</param>
// <param name="prependChild"></param>
Helper to finds or create all nodes specified in elementPath
Helper to finds or create all nodes specified in elementPath
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1614:ElementParameterDocumentationMustHaveText")]
        private static XmlNode FindOrCreateXmlElement(XmlNode parentNode, string elementPath, bool prependChild = false)
        {
            Debug.Assert(parentNode != null, "parentNode != null");
            Debug.Assert(
                parentNode.NodeType == XmlNodeType.Document ||
                parentNode.OwnerDocument != null, "parentNode.OwnerDocument != null");
            XmlNode xmlNode = null;
            var elementNames = elementPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var elementName in elementNames)
            {
                xmlNode = parentNode.SelectSingleNode(elementName);
                if (null == xmlNode)
                {
                    xmlNode = parentNode.OwnerDocument.CreateElement(elementName);
                    if (prependChild)
                    {
                        parentNode.PrependChild(xmlNode);
                    }
                    else
                    {
                        parentNode.AppendChild(xmlNode);
                    }
                }
                parentNode = xmlNode;
            }
            return xmlNode;
        }
[ SuppressMessage ( " " , " " ) ] private static XmlNode FindOrCreateXmlElement ( XmlNode parentNode , string elementPath , bool prependChild = false ) { Debug . Assert ( parentNode != null , " " ) ; Debug . Assert ( parentNode . NodeType == XmlNodeType . Document || parentNode . OwnerDocument != null , " " ) ; XmlNode xmlNode = null ; var elementNames = elementPath . Split ( new [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) ; foreach ( var elementName in elementNames ) { xmlNode = parentNode . SelectSingleNode ( elementName ) ; if ( null == xmlNode ) { xmlNode = parentNode . OwnerDocument . CreateElement ( elementName ) ; if ( prependChild ) { parentNode . PrependChild ( xmlNode ) ; } else { parentNode . AppendChild ( xmlNode ) ; } } parentNode = xmlNode ; } return xmlNode ; }
Helper to finds or create all nodes specified in elementPath
Helper to finds or create all nodes specified in elementPath
parentNode
XmlNode
None
elementPath
string
full path to element separated by '/'
full path to element separated by ' / '
prependChild
bool
None