Browse files

Fixing collection extensions....

  • Loading branch information...
1 parent d7fb0b3 commit bde72836a20806f3c408899052e1777f6b964f56 @jchadwick jchadwick committed Nov 6, 2012
Showing with 13 additions and 9 deletions.
  1. +13 −9 Ebuy.Mvc/Extensions/CollectionExtensions.cs
View
22 Ebuy.Mvc/Extensions/CollectionExtensions.cs
@@ -8,26 +8,30 @@ public static class CollectionExtensions
{
public static IEnumerable<T> Page<T>(this IEnumerable<T> source, int pageIndex, int pageSize)
{
- return Page<T, IEnumerable<T>>(source, pageIndex, pageSize);
- }
+ Contract.Requires(pageIndex >= 0, "Page index cannot be negative");
+ Contract.Requires(pageSize >= 0, "Page size cannot be negative");
- public static IQueryable<T> Page<T>(this IQueryable<T> source, int pageIndex, int pageSize)
- {
- return Page<T, IQueryable<T>>(source, pageIndex, pageSize);
+ int skip = pageIndex * pageSize;
+
+ if (skip > 0)
+ source = source.Skip(skip);
+
+ source = source.Take(pageSize);
+
+ return source;
}
- private static U Page<T,U>(this U source, int pageIndex, int pageSize)
- where U : IEnumerable<T>
+ public static IQueryable<T> Page<T>(this IQueryable<T> source, int pageIndex, int pageSize)
{
Contract.Requires(pageIndex >= 0, "Page index cannot be negative");
Contract.Requires(pageSize >= 0, "Page size cannot be negative");
int skip = pageIndex * pageSize;
if (skip > 0)
- source = (U)source.Skip(skip);
+ source = source.Skip(skip);
- source = (U)source.Take(pageSize);
+ source = source.Take(pageSize);
return source;
}

0 comments on commit bde7283

Please sign in to comment.