// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; using System.Collections.Generic; using System.Collections.ObjectModel; namespace ICSharpCode.ILSpy.Debugger.Tooltips { /// /// A wrapper around IEnumerable<T> with AddNextItems method for pulling additional items /// from underlying IEnumerable<T>. /// Can be used as source for . /// internal class VirtualizingIEnumerable : ObservableCollection { private IEnumerator originalSourceEnumerator; public VirtualizingIEnumerable(IEnumerable originalSource) { if (originalSource == null) throw new ArgumentNullException("originalSource"); this.originalSourceEnumerator = originalSource.GetEnumerator(); } private bool hasNext = true; /// /// False if all items from underlying IEnumerable have already been added. /// public bool HasNext { get { return this.hasNext; } } /// /// Requests next items from underlying IEnumerable source and adds them to the collection. /// public void AddNextItems(int count) { for (int i = 0; i < count; i++) { if (!originalSourceEnumerator.MoveNext()) { this.hasNext = false; break; } this.Add(originalSourceEnumerator.Current); } } } }