Rather than explicitly implementing the interface, unless you have a reason not to, you should generally use an iterator block to create such sequences. It will take care of the boilerplate code, just leaving you with the interesting implementation. A problem like this will generally look something along these lines:
//you can make this private if you want
public static IEnumerable<IList<Foo>> GetPages(int pageSize)
{
IList<Foo> nextGroup = ExecuteQuery();
while (nextGroup.Count == pageSize)
{
yield return nextGroup;
nextGroup = ExecuteQuery();
}
if (nextGroup.Any())
yield return nextGroup;
}
You can then use SelectMany
to flatten out the list of groups into a list of the individual items:
public static IEnumerable<Foo> GetItems(int pageSize)
{
return GetPages(pageSize).SelectMany(x => x);
}