Esempio n. 1
0
        public Node AddChildReference(Guid key)
        {
            if (ChildrenReference == null)
            {
                ChildrenReference = new HashSet <Guid>();
            }

            ChildrenReference.Add(key);
            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Removes the specified node from <see cref="Children" />.
        /// </summary>
        /// <param name="childNode">
        /// The child node to remove.
        /// </param>
        /// <returns>
        /// <see langword="true" /> if the specified node was present in <see cref="Children" />, otherwise <see langword="false" />.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="childNode" /> is <see langword="null" />.
        /// </exception>
        public Boolean RemoveChild(TreeNode <T> childNode)
        {
            childNode.RejectIf().IsNull(nameof(childNode));

            lock (SyncRoot)
            {
                childNode.ParentReference = null;
                return(ChildrenReference.Remove(childNode));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Adds the specified node to <see cref="Children" /> and sets its <see cref="Parent" /> to the current node.
        /// </summary>
        /// <param name="childNode">
        /// The child node to add.
        /// </param>
        /// <param name="enforceDuplicateProhibition">
        /// A value indicating whether or not to reject <paramref name="childNode" /> if the current node already contains a
        /// reference to it.
        /// </param>
        /// <returns>
        /// <see langword="true" /> if the specified node was added to <see cref="Children" />, otherwise <see langword="false" />.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="childNode" /> is <see langword="null" />.
        /// </exception>
        protected Boolean AddChild(TreeNode <T> childNode, Boolean enforceDuplicateProhibition)
        {
            lock (SyncRoot)
            {
                if (Capacity > UnlimitedCapacityValue && ChildrenReference.Count() >= Capacity)
                {
                    return(false);
                }
                else if (enforceDuplicateProhibition && ChildrenReference.Contains(childNode.RejectIf().IsNull(nameof(childNode))))
                {
                    return(false);
                }

                childNode.ParentReference = this;
                ChildrenReference.Add(childNode);
            }

            return(true);
        }