Class Pager<TItem, TConfig, TResponse>
Pager class for iterating through paginated results.
Supports asynchronous enumeration via await foreach and explicit page fetching via NextPageAsync().
public class Pager<TItem, TConfig, TResponse> : IAsyncEnumerable<TItem> where TItem : class
Type Parameters
TItemThe type of items in the pager.
TConfigThe type of configuration for list requests.
TResponseThe type of response from list requests.
- Inheritance
-
Pager<TItem, TConfig, TResponse>
- Implements
-
IAsyncEnumerable<TItem>
- Inherited Members
Constructors
Pager(Func<TConfig, Task<TResponse>>, Func<TResponse, IReadOnlyList<TItem>?>, Func<TResponse, string?>, Func<TResponse, HttpResponse?>, Func<TConfig, string, TConfig>, TConfig, TResponse, int)
Constructs a Pager.
public Pager(Func<TConfig, Task<TResponse>> requestFunc, Func<TResponse, IReadOnlyList<TItem>?> extractItems, Func<TResponse, string?> extractNextPageToken, Func<TResponse, HttpResponse?> extractHttpResponse, Func<TConfig, string, TConfig> updateConfigPageToken, TConfig initialConfig, TResponse initialResponse, int requestedPageSize)
Parameters
requestFuncFunc<TConfig, Task<TResponse>>Function to fetch a page given a config.
extractItemsFunc<TResponse, IReadOnlyList<TItem>>Function to extract items from a response.
extractNextPageTokenFunc<TResponse, string>Function to extract next page token from a response.
extractHttpResponseFunc<TResponse, HttpResponse>Function to extract HTTP response from a response.
updateConfigPageTokenFunc<TConfig, string, TConfig>Function to update config with a new page token.
initialConfigTConfigInitial configuration for the first request.
initialResponseTResponseInitial response from the first request.
requestedPageSizeintThe requested page size.
Properties
Count
Gets the number of items in the current page.
public int Count { get; }
Property Value
CurrentPage
Gets the current page of items.
public IReadOnlyList<TItem> CurrentPage { get; }
Property Value
- IReadOnlyList<TItem>
HasMorePages
Gets a value indicating whether there are more pages available.
public bool HasMorePages { get; }
Property Value
PageSize
Gets the requested page size.
public int PageSize { get; }
Property Value
SdkHttpResponse
Gets the HTTP response for the current page.
public HttpResponse? SdkHttpResponse { get; }
Property Value
Methods
GetAsyncEnumerator(CancellationToken)
Returns an asynchronous enumerator that iterates through all items across all pages.
public IAsyncEnumerator<TItem> GetAsyncEnumerator(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
- IAsyncEnumerator<TItem>
NextPageAsync()
Fetches the next page of items. This makes a new API request.
public Task<bool> NextPageAsync()
Returns
- Task<bool>
A Task<TResult> that represents the asynchronous operation. The task result is
trueif the next page was successfully fetched, orfalseif there are no more pages available.