public void Promote(ThreeItemList<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;
            }
            throw new ArgumentOutOfRangeException("oldList");
        }
Пример #2
0
        public void Promote(ThreeItemList <T> oldList)
        {
            int count = oldList.Count;

            if (6 <= 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;
                }
                throw new ArgumentOutOfRangeException("oldList");
            }
            throw new ArgumentException(System.Xaml.SR.Get("FrugalList_TargetMapCannotHoldAllData", new object[] { oldList.ToString(), this.ToString() }), "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);
        }
 public override object Clone()
 {
     ThreeItemList<T> list = new ThreeItemList<T>();
     list.Promote((ThreeItemList<T>) this);
     return list;
 }