/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. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. namespace ICSharpCode.ILSpy.Debugger.Tooltips
  7. {
  8. /// <summary>
  9. /// A wrapper around IEnumerable&lt;T&gt; with AddNextItems method for pulling additional items
  10. /// from underlying IEnumerable&lt;T&gt;.
  11. /// Can be used as source for <see cref="LazyItemsControl" />.
  12. /// </summary>
  13. internal class VirtualizingIEnumerable<T> : ObservableCollection<T>
  14. {
  15. private IEnumerator<T> originalSourceEnumerator;
  16. public VirtualizingIEnumerable(IEnumerable<T> originalSource)
  17. {
  18. if (originalSource == null)
  19. throw new ArgumentNullException("originalSource");
  20. this.originalSourceEnumerator = originalSource.GetEnumerator();
  21. }
  22. private bool hasNext = true;
  23. /// <summary>
  24. /// False if all items from underlying IEnumerable have already been added.
  25. /// </summary>
  26. public bool HasNext
  27. {
  28. get
  29. {
  30. return this.hasNext;
  31. }
  32. }
  33. /// <summary>
  34. /// Requests next <paramref name="count"/> items from underlying IEnumerable source and adds them to the collection.
  35. /// </summary>
  36. public void AddNextItems(int count)
  37. {
  38. for (int i = 0; i < count; i++) {
  39. if (!originalSourceEnumerator.MoveNext()) {
  40. this.hasNext = false;
  41. break;
  42. }
  43. this.Add(originalSourceEnumerator.Current);
  44. }
  45. }
  46. }
  47. }