/// <summary> /// Initializes a new instance of the <see cref="LinqPagedMetadata{TSource}"/> class. /// </summary> /// <param name="items">The items.</param> /// <param name="criteria">The criteria.</param> /// <exception cref="System.ArgumentNullException"> /// items /// or /// criteria /// </exception> public LinqPagedMetadata(IEnumerable <TSource> items, LinqPagedCriteria criteria) { Items = (items ?? throw new ArgumentNullException(nameof(items))).Count(); Criteria = criteria ?? throw new ArgumentNullException(nameof(criteria)); TotalItems = criteria.TotalItemsAccessor?.Invoke() ?? Items; Index = criteria.Index; Pages = TotalItems > 0 ? (int)Math.Ceiling(TotalItems / (decimal)Criteria.PageSize) : 1; HasOverflowedShowAll = Criteria.ShowAll && Items < TotalItems; EnsureVisiblity(); }
public LinqPagedMetadata(IEnumerable <TSource> items, LinqPagedCriteria criteria) { if (items == null) { throw new ArgumentNullException("items"); } if (criteria == null) { throw new ArgumentNullException("criteria"); } Criteria = criteria; Items = items.Count(); var totalItemsAccessor = criteria.TotalItemsAccessor; TotalItems = (totalItemsAccessor == null ? Items : totalItemsAccessor()); Index = criteria.PageIndex; Pages = (TotalItems > 0 ? (int)Math.Ceiling(TotalItems / (decimal)Criteria.PageSize) : 1); HasOverflowedShowAll = ((Criteria.ShowAll) && (Items < TotalItems)); EnsureVisiblity(); }
/// <summary> /// Gets the metadata. /// </summary> /// <typeparam name="TSource">The type of the t source.</typeparam> /// <param name="source">The source.</param> /// <param name="criteria">The criteria.</param> /// <returns>IPagedMetadata.</returns> public abstract IPagedMetadata GetMetadata <TSource>(IEnumerable <TSource> source, LinqPagedCriteria criteria);
public static IPagedList <TSource> ToPagedList <TSource>(this IEnumerable <TSource> source, LinqPagedCriteria criteria) { if (source == null) { throw new ArgumentNullException("source"); } return(ToPagedList(source.AsQueryable(), criteria)); }
public static TSource[] ToPagedArray <TSource>(this IEnumerable <TSource> source, LinqPagedCriteria criteria, out IPagedMetadata pagedMeta) { if (source == null) { throw new ArgumentNullException("source"); } return(ToPagedArray(source.AsQueryable(), criteria, out pagedMeta)); }
public override IPagedMetadata GetMetadata <TSource>(IQueryable <TSource> source, LinqPagedCriteria criteria) { return(new LinqPagedMetadata <TSource>(source, criteria)); }
public static IPagedList <TSource> ToPagedList <TSource>(this IQueryable <TSource> source, LinqPagedCriteria criteria) { if (source == null) { throw new ArgumentNullException("source"); } if (criteria == null) { throw new ArgumentNullException("criteria"); } var meta = LinqPagedMetadataProviders.Current.GetMetadata <TSource>(source, criteria); int pageSize = criteria.PageSize; int index = meta.Index; if (meta.TotalItems > 0) { return(new PagedList <TSource>((index == 0 ? source.Take(pageSize) : source.Skip(index * pageSize).Take(pageSize)), meta)); } return(new PagedList <TSource>(meta)); }
public static TSource[] ToPagedArray <TSource>(this IQueryable <TSource> source, LinqPagedCriteria criteria, out IPagedMetadata meta) { if (source == null) { throw new ArgumentNullException("source"); } if (criteria == null) { throw new ArgumentNullException("criteria"); } meta = LinqPagedMetadataProviders.Current.GetMetadata <TSource>(source, criteria); int pageSize = criteria.PageSize; int index = meta.Index; if (meta.TotalItems > 0) { return(new Buffer <TSource>(index == 0 ? source.Take(pageSize) : source.Skip(index * pageSize).Take(pageSize)).ToArray()); } return(new TSource[] { }); }
/// <summary> /// Gets the metadata. /// </summary> /// <typeparam name="TSource">The type of the source.</typeparam> /// <param name="source">The source.</param> /// <param name="criteria">The criteria.</param> /// <returns></returns> public override IPagedMetadata GetMetadata <TSource>(IEnumerable <TSource> source, LinqPagedCriteria criteria) => new LinqPagedMetadata <TSource>(source, criteria);
public override IPagedMetadata GetMetadata <TSource>(IQueryable <TSource> source, LinqPagedCriteria criteria) { throw new NotSupportedException(); }
/// <summary> /// To the paged array. /// </summary> /// <typeparam name="TSource">The type of the t source.</typeparam> /// <param name="source">The source.</param> /// <param name="criteria">The criteria.</param> /// <param name="metadata">The metadata.</param> /// <returns>TSource[].</returns> /// <exception cref="System.ArgumentNullException"> /// source /// or /// criteria /// </exception> public static TSource[] ToPagedArray <TSource>(this IEnumerable <TSource> source, LinqPagedCriteria criteria, out IPagedMetadata metadata) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (criteria == null) { throw new ArgumentNullException(nameof(criteria)); } metadata = LinqPagedMetadataProviders.Current.GetMetadata(source, criteria); var pageSize = criteria.PageSize; var index = metadata.Index; return(metadata.TotalItems > 0 ? new Buffer <TSource>(index == 0 ? source.Take(pageSize) : source.Skip(index * pageSize).Take(pageSize)).ToArray() : new TSource[] { }); }