/// <summary> /// Inserts an item into the collection. /// </summary> /// <param name="item">The item to add to the collection.</param> /// <param name="itemToInsertBefore">The item to insert the new item before.</param> internal void InsertBefore(CodeUnit item, CodeUnit itemToInsertBefore) { Param.AssertNotNull(item, "item"); Param.Ignore(itemToInsertBefore, "itemToInsertBefore"); CsLanguageService.Debug.Assert(itemToInsertBefore.Parent != null, "Item is not in this collection."); CsLanguageService.Debug.Assert(itemToInsertBefore.Parent.Children == this, "Item is not in this collection."); CsLanguageService.Debug.Assert( item.ParentReference == null, "The code unit has already been added to a different collection and must be removed from the that collection before it can be added to this one."); if (this.items == null) { this.items = new CodeUnitLinkedList(); } this.items.InsertBefore(item, itemToInsertBefore); item.ParentReference = this.parentReference; }
/// <summary> /// Adds an item to the collection. /// </summary> /// <param name="item">The item to add to the collection.</param> /// <param name="setParent">Indicates whether to set the item's parent to the parent of this collection.</param> internal void Add(CodeUnit item, bool setParent) { Param.AssertNotNull(item, "item"); Param.Ignore(setParent); CsLanguageService.Debug.Assert( item.ParentReference == null, "The code unit has already been added to a different collection and must be removed from the that collection before it can be added to this one."); if (this.items == null) { this.items = new CodeUnitLinkedList(); } this.items.Add(item); if (setParent) { item.ParentReference = this.parentReference; } }
/// <summary> /// Replaces the original item in the list with the new item. /// </summary> /// <param name="originalItem">The original item to remove and replace.</param> /// <param name="newItem">The new item to insert into the list.</param> internal void Replace(CodeUnit originalItem, CodeUnit newItem) { Param.AssertNotNull(originalItem, "originalItem"); Param.AssertNotNull(newItem, "newItem"); CsLanguageService.Debug.Assert( originalItem.ParentReference == this.parentReference, "The original item is not a member of this collection."); CsLanguageService.Debug.Assert( newItem.ParentReference == null, "The new item has already been added to a different collection and must be removed from the that collection before it can be added to this one."); if (this.items == null) { this.items = new CodeUnitLinkedList(); } this.items.Replace(originalItem, newItem); originalItem.ParentReference = null; newItem.ParentReference = this.parentReference; }
/// <summary> /// Inserts an item at the beginning of the collection. /// </summary> /// <param name="item">The item to add to the collection.</param> internal void InsertFirst(CodeUnit item) { Param.AssertNotNull(item, "item"); CsLanguageService.Debug.Assert( item.ParentReference == null, "The code unit has already been added to a different collection and must be removed from the that collection before it can be added to this one."); if (this.items == null) { this.items = new CodeUnitLinkedList(); } if (this.items.Count == 0) { this.items.Add(item); } else { this.items.InsertBefore(item, this.First); } item.ParentReference = this.parentReference; }