/// <summary> /// Get the actual <see cref="PagerItemOptions" /> for a specified <see cref="PagerLayoutElement" />. /// </summary> /// <param name="layoutElement">The <see cref="PagerLayoutElement" /> which indicates the role of the pager item.</param> /// <returns>A <see cref="PagerItemOptions" /> used for the current <see cref="PagerLayoutElement" />.</returns> /// <remarks> /// The <see cref="PagerLayoutElement" /> enum type cannot tell the difference between normal number pages, /// current page, and omitted pages. In order to get more accurate result, please use /// <see cref="GetOptionsFor(PagerItemType)" /> or <see cref="GetOptionsFor(PagerItem)" /> overloads. /// </remarks> /// <exception cref="ArgumentException">The value of <paramref name="layoutElement" /> is not a valid enum item.</exception> public PagerItemOptions GetOptionsFor(PagerLayoutElement layoutElement) { switch (layoutElement) { case PagerLayoutElement.Items: return Normal; case PagerLayoutElement.GoToFirstPageButton: return FirstPageButton; case PagerLayoutElement.GoToLastPageButton: return LastPageButton; case PagerLayoutElement.GoToPreviousPageButton: return PreviousPageButton; case PagerLayoutElement.GoToNextPageButton: return NextPageButton; default: throw new ArgumentException("The value of the argument is not a valid enum item.", nameof(layoutElement)); } }
/// <summary> /// Generate pager items for the specified layout element. /// </summary> /// <param name="element">The layout element to generating the pager items.</param> /// <param name="currentPage">The current page number.</param> /// <param name="totalPage">The count of total pages.</param> /// <param name="options">The options of the pager.</param> /// <returns>The generated all pager items collection for the specified <paramref name="element" />.</returns> /// <exception cref="ArgumentException">The <paramref name="element" /> is not a valid enum item.</exception> private IEnumerable <PagerItem> GenerateItemsForLayoutElement(PagerLayoutElement element, int currentPage, int totalPage, PagerOptions options) { switch (element) { case PagerLayoutElement.Items: return(GeneratePagerNormalItems(currentPage, totalPage, options.ExpandPageItemsForCurrentPage, options.PagerItemsForEndings)); case PagerLayoutElement.GoToFirstPageButton: case PagerLayoutElement.GoToLastPageButton: case PagerLayoutElement.GoToNextPageButton: case PagerLayoutElement.GoToPreviousPageButton: return(new[] { GenerateSpecialItems(currentPage, totalPage, element) }); default: throw new ArgumentException("The value of the argument is not a valid enum item.", nameof(element)); } }
/// <summary> /// Generate a pager item for a special layout element. /// </summary> /// <param name="currentPage">The current page number.</param> /// <param name="totalPage">The count of total pages.</param> /// <param name="element">The <see cref="PagerLayoutElement" /> to generate the <see cref="PagerItem" />.</param> /// <returns>The generated <see cref="PagerItem" /> for the <paramref name="element" />.</returns> /// <exception cref="ArgumentException"> /// The <paramref name="element" /> is <see cref="PagerLayoutElement.Items" />, or it is not /// a valid enum item. /// </exception> private PagerItem GenerateSpecialItems(int currentPage, int totalPage, PagerLayoutElement element) { PagerItemType type; int pageNumber; switch (element) { case PagerLayoutElement.GoToFirstPageButton: type = PagerItemType.First; pageNumber = 1; break; case PagerLayoutElement.GoToLastPageButton: type = PagerItemType.Last; pageNumber = totalPage; break; case PagerLayoutElement.GoToPreviousPageButton: type = PagerItemType.Previous; pageNumber = currentPage - 1; break; case PagerLayoutElement.GoToNextPageButton: type = PagerItemType.Next; pageNumber = currentPage + 1; break; case PagerLayoutElement.Items: throw new ArgumentException("This method is invalid for normal item layout.", nameof(element)); default: throw new ArgumentException("The argument is not a valid enum item.", nameof(element)); } return(new PagerItem { ItemType = type, PageNumber = pageNumber }); }
/// <summary> /// Get the actual <see cref="PagerItemOptions" /> for a specified <see cref="PagerLayoutElement" />. /// </summary> /// <param name="layoutElement">The <see cref="PagerLayoutElement" /> which indicates the role of the pager item.</param> /// <returns>A <see cref="PagerItemOptions" /> used for the current <see cref="PagerLayoutElement" />.</returns> /// <remarks> /// The <see cref="PagerLayoutElement" /> enum type cannot tell the difference between normal number pages, /// current page, and omitted pages. In order to get more accurate result, please use /// <see cref="GetOptionsFor(PagerItemType)" /> or <see cref="GetOptionsFor(PagerItem)" /> overloads. /// </remarks> /// <exception cref="ArgumentException">The value of <paramref name="layoutElement" /> is not a valid enum item.</exception> public PagerItemOptions GetOptionsFor(PagerLayoutElement layoutElement) { switch (layoutElement) { case PagerLayoutElement.Items: return(Normal); case PagerLayoutElement.GoToFirstPageButton: return(FirstPageButton); case PagerLayoutElement.GoToLastPageButton: return(LastPageButton); case PagerLayoutElement.GoToPreviousPageButton: return(PreviousPageButton); case PagerLayoutElement.GoToNextPageButton: return(NextPageButton); default: throw new ArgumentException("The value of the argument is not a valid enum item.", nameof(layoutElement)); } }
/// <summary> /// Generate pager items for the specified layout element. /// </summary> /// <param name="element">The layout element to generating the pager items.</param> /// <param name="currentPage">The current page number.</param> /// <param name="totalPage">The count of total pages.</param> /// <param name="options">The options of the pager.</param> /// <returns>The generated all pager items collection for the specified <paramref name="element" />.</returns> /// <exception cref="ArgumentException">The <paramref name="element" /> is not a valid enum item.</exception> private IEnumerable<PagerItem> GenerateItemsForLayoutElement(PagerLayoutElement element, int currentPage, int totalPage, PagerOptions options) { switch (element) { case PagerLayoutElement.Items: return GeneratePagerNormalItems(currentPage, totalPage, options.ExpandPageItemsForCurrentPage, options.PagerItemsForEndings); case PagerLayoutElement.GoToFirstPageButton: case PagerLayoutElement.GoToLastPageButton: case PagerLayoutElement.GoToNextPageButton: case PagerLayoutElement.GoToPreviousPageButton: return new[] {GenerateSpecialItems(currentPage, totalPage, element)}; default: throw new ArgumentException("The value of the argument is not a valid enum item.", nameof(element)); } }
/// <summary> /// Generate a pager item for a special layout element. /// </summary> /// <param name="currentPage">The current page number.</param> /// <param name="totalPage">The count of total pages.</param> /// <param name="element">The <see cref="PagerLayoutElement" /> to generate the <see cref="PagerItem" />.</param> /// <returns>The generated <see cref="PagerItem" /> for the <paramref name="element" />.</returns> /// <exception cref="ArgumentException"> /// The <paramref name="element" /> is <see cref="PagerLayoutElement.Items" />, or it is not /// a valid enum item. /// </exception> private PagerItem GenerateSpecialItems(int currentPage, int totalPage, PagerLayoutElement element) { PagerItemType type; int pageNumber; switch (element) { case PagerLayoutElement.GoToFirstPageButton: type = PagerItemType.First; pageNumber = 1; break; case PagerLayoutElement.GoToLastPageButton: type = PagerItemType.Last; pageNumber = totalPage; break; case PagerLayoutElement.GoToPreviousPageButton: type = PagerItemType.Previous; pageNumber = currentPage - 1; break; case PagerLayoutElement.GoToNextPageButton: type = PagerItemType.Next; pageNumber = currentPage + 1; break; case PagerLayoutElement.Items: throw new ArgumentException("This method is invalid for normal item layout.", nameof(element)); default: throw new ArgumentException("The argument is not a valid enum item.", nameof(element)); } return new PagerItem { ItemType = type, PageNumber = pageNumber }; }