示例#1
0
        /// <summary>
        /// 同じ階層でこの要素の直前に指定した要素を挿入します。</summary>
        ///
        public void InsertBefore(TreeElement anElement)
        {
            if (anElement == null)
            {
                throw new ArgumentNullException("anElement");
            }
            if (this.IsTop)
            {
                throw new InvalidOperationException("ルート要素の前後に要素を挿入することは出来ません。");
            }
            if (this.IsContainsStructure(anElement))
            {
                throw new InvalidOperationException("追加しようとした要素は既にこの要素を含む構造内に含まれています。");
            }

            if (this.Index == 0)
            {
                this.StructureReferenceElements.Add(anElement);
                anElement.SetParentElement(this.Parent);
                this.Parent.ChildElements.Insert(0, anElement);
            }
            else
            {
                this.StructureReferenceElements.Add(anElement);
                anElement.SetParentElement(this.Parent);
                this.Parent.ChildElements.Insert(this.Index, anElement);
            }
        }
示例#2
0
        /// <summary>
        /// この要素の子要素の先頭へ指定した要素を挿入します。</summary>
        ///
        public void AddPrependChild(TreeElement anElement)
        {
            if (anElement == null)
            {
                throw new ArgumentNullException("anElement");
            }
            if (Kind != TreeElementKind.Composite)
            {
                throw new InvalidOperationException("種類が Composite 以外の要素へ子要素を追加することは出来ません。");
            }
            if (this.IsContainsStructure(anElement))
            {
                throw new InvalidOperationException("追加しようとした要素は既にこの要素を含む階層内に存在しています。");
            }

            if (this.HasChild)
            {
                this.StructureReferenceElements.Add(anElement);
                anElement.SetParentElement(this);
                this.ChildElements.Insert(0, anElement);
            }
            else
            {
                this.Add(anElement);
            }
        }