Table of Contents

Class Pager<TItem, TConfig, TResponse>

Namespace
Google.GenAI
Assembly
Google.GenAI.dll

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

TItem

The type of items in the pager.

TConfig

The type of configuration for list requests.

TResponse

The type of response from list requests.

Inheritance
Pager<TItem, TConfig, TResponse>
Implements
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

requestFunc Func<TConfig, Task<TResponse>>

Function to fetch a page given a config.

extractItems Func<TResponse, IReadOnlyList<TItem>>

Function to extract items from a response.

extractNextPageToken Func<TResponse, string>

Function to extract next page token from a response.

extractHttpResponse Func<TResponse, HttpResponse>

Function to extract HTTP response from a response.

updateConfigPageToken Func<TConfig, string, TConfig>

Function to update config with a new page token.

initialConfig TConfig

Initial configuration for the first request.

initialResponse TResponse

Initial response from the first request.

requestedPageSize int

The requested page size.

Properties

Count

Gets the number of items in the current page.

public int Count { get; }

Property Value

int

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

bool

PageSize

Gets the requested page size.

public int PageSize { get; }

Property Value

int

SdkHttpResponse

Gets the HTTP response for the current page.

public HttpResponse? SdkHttpResponse { get; }

Property Value

HttpResponse

Methods

GetAsyncEnumerator(CancellationToken)

Returns an asynchronous enumerator that iterates through all items across all pages.

public IAsyncEnumerator<TItem> GetAsyncEnumerator(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

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 true if the next page was successfully fetched, or false if there are no more pages available.