/// <inheritdoc /> public IEnumerator <TElement> GetEnumerator() { lock (_originSet) { if (_elementCache != null) { return(_elementCache.GetEnumerator()); } // Copy all matching items into the cache _elementCache = new LinearList <TElement>(); using (FilterIterator itr = new FilterIterator(_originSet.GetEnumerator(), _wherePredicate)) { while (itr.MoveNext()) { _elementCache.Add(itr.Current); } } return(_elementCache.GetEnumerator()); } }
/// <summary> /// Returns a newly created array that contains all items of the given sequence <paramref name="sequence"/>. /// </summary> /// <param name="sequence">Sequence to process</param> /// <returns>Array of all sequence items</returns> public static object[] ToArray(this IEnumerable sequence) { // Check if it's already an array if (sequence is object[] objectArray) { return(objectArray); } // Check if we need just to perform a copy if (sequence is ICollection objectCollection) { objectArray = new object[objectCollection.Count]; objectCollection.CopyTo(objectArray, 0); return(objectArray); } // Process items LinearList <object> linkedList = new LinearList <object>(); sequence.ForEach(linkedList.Add); object[] resultingArray = linkedList.ToArray(); return(resultingArray); }
/// <summary> /// Returns a newly created array that contains all items of the given sequence <paramref name="sequence"/>. /// </summary> /// <typeparam name="TItem">Type of sequence items</typeparam> /// <param name="sequence">Sequence to process</param> /// <returns>Array of all sequence items</returns> public static TItem[] ToArray <TItem>(this IEnumerable <TItem> sequence) { // Check if it's already an array if (sequence is TItem[] itemArray) { return(itemArray); } // Check if we need just to perform a copy if (sequence is ICollection <TItem> itemCollection) { itemArray = new TItem[itemCollection.Count]; itemCollection.CopyTo(itemArray, 0); return(itemArray); } // Process items LinearList <TItem> linkedList = new LinearList <TItem>(); sequence.ForEach(linkedList.Add); TItem[] resultingArray = linkedList.ToArray(); return(resultingArray); }