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