Пример #1
0
        //// Validates this node and its children. Recursive. Order of children and attributes do not matter.
        /// <summary>
        /// NOT IMPLEMENTED.
        /// </summary>
        /// <param name="other">The <paramref name="other"/>.</param>
        /// <param name="update">If true, copy missing nodes and attributes from <paramref name="other"/>.</param>
        /// <param name="trim">If true, remove nodes and attributes that don't appear in <paramref name="other"/>.</param>
        /// <param name="ignoreRoot">If true, ignore root node.</param>
        /// <returns>A bool.</returns>
        public bool Validate(Node other, bool update, bool trim, bool ignoreSelf)
        {
            bool valid = true;

            valid &= Key == other.Key;

            // Attribute check
            List <Attribute> missingAttributes = new List <Attribute>();

            for (int i = 0; i < other.Attributes.Count; i++)
            {
                if (!Attributes.ContainsKey(other.Attributes[i].Key))
                {
                    missingAttributes.Add(new Attribute(other.Attributes[i]));
                }
            }

            // Add missing attributes
            if (update)
            {
                Attributes.Set(missingAttributes);
            }

            // Trim extra attributes
            if (trim)
            {
                List <Attribute> extraAttributes = new List <Attribute>();
                for (int i = 0; i < Attributes.Count; i++)
                {
                    if (!other.Attributes.ContainsKey(Attributes[i].Key))
                    {
                        valid = false;
                        extraAttributes.Add(new Attribute(Attributes[i]));
                    }
                }

                Attributes.Remove(extraAttributes);
            }

            // Children
            List <string> otherKeys = other.GetKeys();

            foreach (string otherKey in otherKeys)
            {
                List <Node> nodesWithKey = FindChildren(otherKey);
                foreach (Node child in nodesWithKey)
                {
                }
            }

            return(valid);
        }