/// <summary>
        ///     Checks if this sub tree contains the specified node.
        /// </summary>
        /// <param name="node">The node to check for.</param>
        /// <returns><c>true</c> if the sub tree contains the <param name="node">node</param>, <c>false</c> otherwise.</returns>
        private bool Contains(XmlNodeViewModel node)
        {
            var nodes = new[] { this };

            foreach (var pathNode in node.GetPath())
            {
                var found = nodes.FirstOrDefault(x => x.Equals(pathNode));

                if (found == null)
                {
                    return(false);
                }

                nodes = found.Children.ToArray();
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        ///     Adds one node of a tree to another.
        /// </summary>
        /// <param name="node">The node to add.</param>
        public void AddToXml(XmlNodeViewModel node)
        {
            var nodes = this.Xml;
            XmlNodeViewModel parent = null;

            foreach (var pathNode in node.GetPath())
            {
                var found = nodes.FirstOrDefault(x => x.Equals(pathNode));

                if (found == null)
                {
                    found = pathNode.Clone();
                    parent?.AddChild(found);
                }

                parent = found;
                nodes  = parent.Children.ToArray();
            }

            this.Compare(null);
        }