Пример #1
0
        public void Promote(SixItemList <T> oldList)
        {
            int count = oldList.Count;

            this.SetCount(oldList.Count);
            switch (count)
            {
            case 0:
                break;

            case 1:
                this.SetAt(0, oldList.EntryAt(0));
                break;

            case 2:
                this.SetAt(0, oldList.EntryAt(0));
                this.SetAt(1, oldList.EntryAt(1));
                break;

            case 3:
                this.SetAt(0, oldList.EntryAt(0));
                this.SetAt(1, oldList.EntryAt(1));
                this.SetAt(2, oldList.EntryAt(2));
                break;

            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));
                break;

            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));
                break;

            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));
                break;

            default:
                throw new ArgumentOutOfRangeException("index");
            }
        }
Пример #2
0
        public int Add(T value)
        {
            if (this._listStore == null)
            {
                this._listStore = (FrugalListBase <T>) new SingleItemList <T>();
            }
            FrugalListStoreState frugalListStoreState = this._listStore.Add(value);

            if (frugalListStoreState != FrugalListStoreState.Success)
            {
                if (FrugalListStoreState.ThreeItemList == frugalListStoreState)
                {
                    ThreeItemList <T> threeItemList = new ThreeItemList <T>();
                    threeItemList.Promote(this._listStore);
                    int num = (int)threeItemList.Add(value);
                    this._listStore = (FrugalListBase <T>)threeItemList;
                }
                else if (FrugalListStoreState.SixItemList == frugalListStoreState)
                {
                    SixItemList <T> sixItemList = new SixItemList <T>();
                    sixItemList.Promote(this._listStore);
                    this._listStore = (FrugalListBase <T>)sixItemList;
                    int num = (int)sixItemList.Add(value);
                    this._listStore = (FrugalListBase <T>)sixItemList;
                }
                else
                {
                    if (FrugalListStoreState.Array != frugalListStoreState)
                    {
                        throw new InvalidOperationException("FrugalList_CannotPromoteBeyondArray");
                    }
                    ArrayItemList <T> arrayItemList = new ArrayItemList <T>(this._listStore.Count + 1);
                    arrayItemList.Promote(this._listStore);
                    this._listStore = (FrugalListBase <T>)arrayItemList;
                    int num = (int)arrayItemList.Add(value);
                    this._listStore = (FrugalListBase <T>)arrayItemList;
                }
            }
            return(this._listStore.Count - 1);
        }