Пример #1
0
        public Node AddChildReference(Guid key)
        {
            if (ChildrenReference == null)
            {
                ChildrenReference = new HashSet <Guid>();
            }

            ChildrenReference.Add(key);
            return(this);
        }
Пример #2
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);
        }