public override object Clone() { SixItemList <T> list = new SixItemList <T>(); list.Promote((SixItemList <T>) this); return(list); }
public void Promote(SixItemList <T> oldList) { int count = oldList.Count; this.SetCount(oldList.Count); switch (count) { case 0: return; case 1: this.SetAt(0, oldList.EntryAt(0)); return; case 2: this.SetAt(0, oldList.EntryAt(0)); this.SetAt(1, oldList.EntryAt(1)); return; case 3: this.SetAt(0, oldList.EntryAt(0)); this.SetAt(1, oldList.EntryAt(1)); this.SetAt(2, oldList.EntryAt(2)); return; case 4: this.SetAt(0, oldList.EntryAt(0)); this.SetAt(1, oldList.EntryAt(1)); this.SetAt(2, oldList.EntryAt(2)); this.SetAt(3, oldList.EntryAt(3)); return; case 5: this.SetAt(0, oldList.EntryAt(0)); this.SetAt(1, oldList.EntryAt(1)); this.SetAt(2, oldList.EntryAt(2)); this.SetAt(3, oldList.EntryAt(3)); this.SetAt(4, oldList.EntryAt(4)); return; case 6: this.SetAt(0, oldList.EntryAt(0)); this.SetAt(1, oldList.EntryAt(1)); this.SetAt(2, oldList.EntryAt(2)); this.SetAt(3, oldList.EntryAt(3)); this.SetAt(4, oldList.EntryAt(4)); this.SetAt(5, oldList.EntryAt(5)); return; } throw new ArgumentOutOfRangeException("oldList"); }
public int Add(T value) { if (this._listStore == null) { this._listStore = new SingleItemList <T>(); } FrugalListStoreState state = this._listStore.Add(value); if (state != FrugalListStoreState.Success) { if (FrugalListStoreState.ThreeItemList != state) { if (FrugalListStoreState.SixItemList != state) { if (FrugalListStoreState.Array != state) { throw new InvalidOperationException(System.Xaml.SR.Get("FrugalList_CannotPromoteBeyondArray")); } ArrayItemList <T> list3 = new ArrayItemList <T>(this._listStore.Count + 1); list3.Promote(this._listStore); this._listStore = list3; list3.Add(value); this._listStore = list3; } else { SixItemList <T> list2 = new SixItemList <T>(); list2.Promote(this._listStore); this._listStore = list2; list2.Add(value); this._listStore = list2; } } else { ThreeItemList <T> list = new ThreeItemList <T>(); list.Promote(this._listStore); list.Add(value); this._listStore = list; } } return(this._listStore.Count - 1); }