Beispiel #1
0
        public static void Resize <T>(IList <T> list, int newCount)
        {
            Validate.Begin().IsNotNull <IList <T> >(list, "list").IsNotNegative(newCount, "newCount").Check();
            SegmentedList <T> list2 = list as SegmentedList <T>;

            if (list2 != null)
            {
                list2.Resize(newCount, false, true);
            }
            else
            {
                int count = list.Count;
                if (newCount != count)
                {
                    if (newCount == 0)
                    {
                        list.Clear();
                    }
                    else if (newCount < count)
                    {
                        int num2 = list.Count - newCount;
                        list.RemoveRange <T>(list.Count - num2, num2);
                    }
                    else if (newCount > count)
                    {
                        int num3 = newCount - list.Count;
                        list.AddDefaults <T>(num3);
                    }
                }
            }
        }
Beispiel #2
0
        public static void Resize <T>(this IList <T> list, int newCount)
        {
            Validate.IsNotNull <IList <T> >(list, "list");
            int count = list.Count;

            if (count != newCount)
            {
                List <T> list2 = list as List <T>;
                if (list2 != null)
                {
                    if (newCount > count)
                    {
                        list2.AddRange(Enumerable.Repeat <T>(default(T), newCount - count));
                    }
                    else
                    {
                        list2.RemoveRange(newCount, count - newCount);
                    }
                }
                else
                {
                    SegmentedList <T> list3 = list as SegmentedList <T>;
                    if (list3 != null)
                    {
                        list3.Resize(newCount, true, true);
                    }
                    else
                    {
                        SegmentedListStruct <T>?nullable = list as SegmentedListStruct <T>?;
                        if (nullable.HasValue)
                        {
                            nullable.Value.Source.Resize(newCount, true, true);
                        }
                        else
                        {
                            UncheckedSegmentedListStruct <T>?nullable2 = list as UncheckedSegmentedListStruct <T>?;
                            if (nullable2.HasValue)
                            {
                                nullable2.Value.Source.Resize(newCount, true, true);
                            }
                            else if (newCount > count)
                            {
                                list.AddDefaults <T>(newCount - count);
                            }
                            else
                            {
                                list.RemoveRange <T>(newCount, count - newCount);
                            }
                        }
                    }
                }
            }
        }