BrightIdeasSoftware.ObjectListView.EnumerableToArray C# (CSharp) Method

EnumerableToArray() public static method

Convert the given enumerable into an ArrayList as efficiently as possible

When we move to .NET 3.5, we can use LINQ and not need this method.

public static EnumerableToArray ( IEnumerable collection, bool alwaysCreate ) : ArrayList
collection IEnumerable The source collection
alwaysCreate bool If true, this method will always create a new /// collection.
return ArrayList
        public static ArrayList EnumerableToArray(IEnumerable collection, bool alwaysCreate)
        {
            if (collection == null)
                return new ArrayList();

            if (!alwaysCreate) {
                ArrayList array = collection as ArrayList;
                if (array != null)
                    return array;

                IList iList = collection as IList;
                if (iList != null)
                    return ArrayList.Adapter(iList);
            }

            ICollection iCollection = collection as ICollection;
            if (iCollection != null)
                return new ArrayList(iCollection);

            ArrayList newObjects = new ArrayList();
            foreach (object x in collection)
                newObjects.Add(x);
            return newObjects;
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Build our filtered list from our full list.
        /// </summary>
        protected void FilterObjects()
        {
            if (!this.listView.UseFiltering || (this.modelFilter == null && this.listFilter == null))
            {
                this.filteredObjectList = new ArrayList(this.fullObjectList);
                return;
            }

            IEnumerable objects = (this.listFilter == null) ?
                                  this.fullObjectList : this.listFilter.Filter(this.fullObjectList);

            // Apply the object filter if there is one
            if (this.modelFilter == null)
            {
                this.filteredObjectList = ObjectListView.EnumerableToArray(objects, false);
            }
            else
            {
                this.filteredObjectList = new ArrayList();
                foreach (object model in objects)
                {
                    if (this.modelFilter.Filter(model))
                    {
                        this.filteredObjectList.Add(model);
                    }
                }
            }
        }
All Usage Examples Of BrightIdeasSoftware.ObjectListView::EnumerableToArray
ObjectListView