I'm using Troy Goode's paged List in my project.
Normally you just feed it an IEnumerable, a startindex and an item count and it all works.
Now however I'm trying to feed it an IEnumerable I generate as follows:
private static IEnumerable<Color> GetColors(Query query)
{
IndexSearcher searcher = new IndexSearcher(luceneIndexpath);
Hits hitColl = searcher.Search(query);
//Get all the unique colorId's
List<int> ids = new List<int>();
int id = 0;
for (int i = 0; i < hitColl.Length(); i++)
{
if (Int32.TryParse(hitColl.Doc(i).GetField("id").StringValue(), out id))
ids.Add(id);
}
foreach (int uniqueId in ids.Distinct<int>())
{
yield return ColorService.GetColor(uniqueId);
}
}
--EDIT-- The pagedList works, but requests the yield for ALL my Color objects instead of only the paged ones. This off course defeats the whole use of PagedList and can result in massive enumerations.
--EDIT--
What I think I need is a way to implement Count() so I can make it return the count from ids.Distinct(int) instead of creating all the objects through ColorService.GetColor() and then counting that list.