# Class PageStreamer&lt;TResource, TRequest, TResponse, TToken&gt; (1.73.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [1.73.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests.PageStreamer-4)
- [1.69.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.69.0/Google.Apis.Requests.PageStreamer-4)
- [1.68.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.68.0/Google.Apis.Requests.PageStreamer-4)
- [1.60.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.60.0/Google.Apis.Requests.PageStreamer-4)
- [1.59.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.59.0/Google.Apis.Requests.PageStreamer-4)
- [1.55.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.55.0/Google.Apis.Requests.PageStreamer-4)
- [1.50.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.50.0/Google.Apis.Requests.PageStreamer-4)

    public sealed class PageStreamer<TResource, TRequest, TResponse, TToken> where TRequest : IClientServiceRequest<TResponse> where TToken : class

A page streamer is a helper to provide both synchronous and asynchronous page streaming
of a listable or queryable resource.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> PageStreamer\<TResource, TRequest, TResponse, TToken\>

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Apis.Requests](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests)

## Assembly

Google.Apis.dll

| ## Type Parameters ||
|---|---|
| **Name** | **Description** |
| `TResource` | The type of resource being paginated |
| `TRequest` | The type of request used to fetch pages |
| `TResponse` | The type of response obtained when fetching pages |
| `TToken` | The type of the "next page token", which must be a reference type; a null reference for a token indicates the end of a stream of pages. |

## Remarks


The expected usage pattern is to create a single paginator for a resource collection,
and then use the instance methods to obtain paginated results.

## Example

To construct a page streamer to return snippets from the YouTube v3 Data API, you might use code
such as the following. The pattern for other APIs would be very similar, with the `request.PageToken`,
`response.NextPageToken` and `response.Items` properties potentially having different names. Constructing
the page streamer doesn't require any service references or authentication, so it's completely safe to perform this
in a type initializer.

    using Google.Apis.YouTube.v3;
    using Google.Apis.YouTube.v3.Data;
    ...
    private static readonly snippetPageStreamer = new PageStreamer<SearchResult, SearchResource.ListRequest, SearchListResponse, string>(
        (request, token) => request.PageToken = token,
        response => response.NextPageToken,
        response => response.Items);

## Constructors

### PageStreamer(Action\<TRequest, TToken\>, Func\<TResponse, TToken\>, Func\<TResponse, IEnumerable\<TResource\>\>)

    public PageStreamer(Action<TRequest, TToken> requestModifier, Func<TResponse, TToken> tokenExtractor, Func<TResponse, IEnumerable<TResource>> resourceExtractor)

Creates a paginator for later use.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `requestModifier` | `https://learn.microsoft.com/dotnet/api/system.action-2` Action to modify a request to include the specified page token. Must not be null. |
| `tokenExtractor` | `https://learn.microsoft.com/dotnet/api/system.func-2` Function to extract the next page token from a response. Must not be null. |
| `resourceExtractor` | `https://learn.microsoft.com/dotnet/api/system.func-2https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1` Function to extract a sequence of resources from a response. Must not be null, although it can return null if it is passed a response which contains no resources. |

## Methods

### Fetch(TRequest)

    public IEnumerable<TResource> Fetch(TRequest request)

Lazily fetches resources a page at a time.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `request` | `TRequest` The initial request to send. If this contains a page token, that token is maintained. This will be modified with new page tokens over time, and should not be changed by the caller. (The caller should clone the request if they want an independent object to use in other calls or to modify.) Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1` | A sequence of resources, which are fetched a page at a time. Must not be null. |

### FetchAllAsync(TRequest, CancellationToken)

    public Task<IList<TResource>> FetchAllAsync(TRequest request, CancellationToken cancellationToken)

Asynchronously (but eagerly) fetches a complete set of resources, potentially making multiple requests.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `TRequest` The initial request to send. If this contains a page token, that token is maintained. This will be modified with new page tokens over time, and should not be changed by the caller. (The caller should clone the request if they want an independent object to use in other calls or to modify.) Must not be null. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1` | A sequence of resources, which are fetched asynchronously and a page at a time. |

## Extension Method

[Utilities.ThrowIfNull\<T\>(T, string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Utilities#Google_Apis_Util_Utilities_ThrowIfNull__1___0_System_String_)