| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.ComponentModel; |
| | 6 | |
|
| | 7 | | namespace Azure |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// A single <see cref="Page{T}"/> of values from a request that may return |
| | 11 | | /// zero or more <see cref="Page{T}"/>s of values. |
| | 12 | | /// </summary> |
| | 13 | | /// <typeparam name="T">The type of values.</typeparam> |
| | 14 | | public abstract class Page<T> |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Gets the values in this <see cref="Page{T}"/>. |
| | 18 | | /// </summary> |
| | 19 | | public abstract IReadOnlyList<T> Values { get; } |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Gets the continuation token used to request the next |
| | 23 | | /// <see cref="Page{T}"/>. The continuation token may be null or |
| | 24 | | /// empty when there are no more pages. |
| | 25 | | /// </summary> |
| | 26 | | public abstract string? ContinuationToken { get; } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Gets the <see cref="Response"/> that provided this |
| | 30 | | /// <see cref="Page{T}"/>. |
| | 31 | | /// </summary> |
| | 32 | | public abstract Response GetRawResponse(); |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Creates a new <see cref="Page{T}"/>. |
| | 36 | | /// </summary> |
| | 37 | | /// <param name="values"> |
| | 38 | | /// The values in this <see cref="Page{T}"/>. |
| | 39 | | /// </param> |
| | 40 | | /// <param name="continuationToken"> |
| | 41 | | /// The continuation token used to request the next <see cref="Page{T}"/>. |
| | 42 | | /// </param> |
| | 43 | | /// <param name="response"> |
| | 44 | | /// The <see cref="Response"/> that provided this <see cref="Page{T}"/>. |
| | 45 | | /// </param> |
| | 46 | | #pragma warning disable CA1000 // Do not declare static members on generic types |
| | 47 | | public static Page<T> FromValues(IReadOnlyList<T> values, string? continuationToken, Response response) |
| | 48 | | #pragma warning restore CA1000 // Do not declare static members on generic types |
| | 49 | | { |
| 0 | 50 | | return new PageCore(values, continuationToken, response); |
| | 51 | | } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Creates a string representation of an <see cref="Page{T}"/>. |
| | 55 | | /// </summary> |
| | 56 | | /// <returns> |
| | 57 | | /// A string representation of an <see cref="Page{T}"/>. |
| | 58 | | /// </returns> |
| | 59 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 60 | | public override string ToString() => base.ToString(); |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// Check if two <see cref="Page{T}"/> instances are equal. |
| | 64 | | /// </summary> |
| | 65 | | /// <param name="obj">The instance to compare to.</param> |
| | 66 | | /// <returns>True if they're equal, false otherwise.</returns> |
| | 67 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 68 | | public override bool Equals(object? obj) => base.Equals(obj); |
| | 69 | |
|
| | 70 | | /// <summary> |
| | 71 | | /// Get a hash code for the <see cref="Page{T}"/>. |
| | 72 | | /// </summary> |
| | 73 | | /// <returns>Hash code for the <see cref="Page{T}"/>.</returns> |
| | 74 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 75 | | public override int GetHashCode() => base.GetHashCode(); |
| | 76 | |
|
| | 77 | | private class PageCore : Page<T> |
| | 78 | | { |
| | 79 | | private readonly Response _response; |
| | 80 | |
|
| 0 | 81 | | public PageCore(IReadOnlyList<T> values, string? continuationToken, Response response) |
| | 82 | | { |
| 0 | 83 | | _response = response; |
| 0 | 84 | | Values = values; |
| 0 | 85 | | ContinuationToken = continuationToken; |
| 0 | 86 | | } |
| | 87 | |
|
| 0 | 88 | | public override IReadOnlyList<T> Values { get; } |
| 0 | 89 | | public override string? ContinuationToken { get; } |
| 0 | 90 | | public override Response GetRawResponse() => _response; |
| | 91 | | } |
| | 92 | | } |
| | 93 | | } |