PageRenderTime 28ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/Debugger/ILSpy.Debugger/ToolTips/VirtualizingIEnumerable.cs

http://github.com/icsharpcode/ILSpy
C# | 53 lines | 34 code | 6 blank | 13 comment | 4 complexity | 547ceb188121eda174abeec3a554235a MD5 | raw file
 1// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 2// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Collections.ObjectModel;
 7
 8namespace ICSharpCode.ILSpy.Debugger.Tooltips
 9{
10	/// <summary>
11	/// A wrapper around IEnumerable&lt;T&gt; with AddNextItems method for pulling additional items 
12	/// from underlying IEnumerable&lt;T&gt;.
13	/// Can be used as source for <see cref="LazyItemsControl" />.
14	/// </summary>
15	internal class VirtualizingIEnumerable<T> : ObservableCollection<T>
16	{
17		private IEnumerator<T> originalSourceEnumerator;
18
19		public VirtualizingIEnumerable(IEnumerable<T> originalSource)
20		{
21			if (originalSource == null)
22				throw new ArgumentNullException("originalSource");
23
24			this.originalSourceEnumerator = originalSource.GetEnumerator();
25		}
26
27		private bool hasNext = true;
28		/// <summary>
29		/// False if all items from underlying IEnumerable have already been added.
30		/// </summary>
31		public bool HasNext
32		{
33			get
34			{
35				return this.hasNext;
36			}
37		}
38
39		/// <summary>
40		/// Requests next <paramref name="count"/> items from underlying IEnumerable source and adds them to the collection.
41		/// </summary>
42		public void AddNextItems(int count)
43		{
44			for (int i = 0; i < count; i++) {
45				if (!originalSourceEnumerator.MoveNext()) {
46					this.hasNext = false;
47					break;
48				}
49				this.Add(originalSourceEnumerator.Current);
50			}
51		}
52	}
53}