Method ReadItemsAsync
ReadItemsAsync<TItem>(Stream, JsonTypeInfo<TItem>, CancellationToken)
Reads the items from a streaming response body. Ping records are skipped, error records are thrown as the corresponding ApiException, and the enumeration completes when the end record is received. Null items are yielded as null, so a nullable item type should be used if the endpoint can produce them.
Declaration
public static IAsyncEnumerable<TItem> ReadItemsAsync<TItem>(Stream stream, JsonTypeInfo<TItem> itemTypeInfo, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The response body stream. |
| JsonTypeInfo<TItem> | itemTypeInfo | The JSON type info used to deserialize items. |
| CancellationToken | cancellationToken | A token that cancels the read. |
Returns
| Type | Description |
|---|---|
| IAsyncEnumerable<TItem> |
Type Parameters
| Name | Description |
|---|---|
| TItem | The item type. |
Exceptions
| Type | Condition |
|---|---|
| ApiException | The stream contained an error record. |
| HttpIOException | The stream ended before an end or error record was received. |
| FormatException | The stream contained an unrecognized record. |
ReadItemsAsync<TItem>(Stream, JsonSerializerOptions, CancellationToken)
Reads the items from a streaming response body using the specified serializer options to deserialize items.
Declaration
public static IAsyncEnumerable<TItem> ReadItemsAsync<TItem>(Stream stream, JsonSerializerOptions serializerOptions, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The response body stream. |
| JsonSerializerOptions | serializerOptions | The serializer options used to deserialize items. |
| CancellationToken | cancellationToken | A token that cancels the read. |
Returns
| Type | Description |
|---|---|
| IAsyncEnumerable<TItem> |
Type Parameters
| Name | Description |
|---|---|
| TItem | The item type. |
Exceptions
| Type | Condition |
|---|---|
| ApiException | The stream contained an error record. |
| HttpIOException | The stream ended before an end or error record was received. |
| FormatException | The stream contained an unrecognized record. |