Class Result<T>
- Namespace
- Twikit
- Assembly
- Twikit.dll
複数件の結果を保持するクラス。NextAsync() でさらに結果を取得できます。 通常のリストと同じくインデックスでアクセスでき、foreach で列挙できます。
public sealed class Result<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
T要素の型。
- Inheritance
-
Result<T>
- Implements
-
IEnumerable<T>
- Inherited Members
Remarks
ページ送りは NextAsync() で行い、NextCursor を自分でメソッドに
渡し直さないでください。 X はほとんどのエンドポイントで count を無視し、
要求よりはるかに多く(20 件要求して 70 ユーザーなど)返してきます。余剰分はこの
オブジェクトの内部に蓄えられ、次のリクエストを送る前に NextAsync() から
順に返されます。NextCursor はすでにその余剰分を飛び越えた位置を指すため、
カーソルを渡してメソッドを呼び直すと蓄えた分を丸ごと読み飛ばします。
終了判定はカーソルではなくページの中身で行ってください。カーソルは位置を示すだけで
「続きがある」保証ではなく、X は空ページにもカーソルを返します。while (page.NextCursor != null)
は同じ空ページを取り続けますが、while (page.Count > 0) は空ページが返った時点で終わります。
Constructors
Result(IEnumerable<T>, Func<Task<Result<T>>>?, string?, Func<Task<Result<T>>>?, string?, IEnumerable<T>?, int?)
public Result(IEnumerable<T> results, Func<Task<Result<T>>>? fetchNextResult = null, string? nextCursor = null, Func<Task<Result<T>>>? fetchPreviousResult = null, string? previousCursor = null, IEnumerable<T>? overflow = null, int? pageSize = null)
Parameters
resultsIEnumerable<T>fetchNextResultFunc<Task<Result<T>>>nextCursorstringfetchPreviousResultFunc<Task<Result<T>>>previousCursorstringoverflowIEnumerable<T>pageSizeint?
Properties
Count
Gets the number of elements in the collection.
public int Count { get; }
Property Value
- int
The number of elements in the collection.
Cursor
NextCursor の別名。
public string? Cursor { get; }
Property Value
this[int]
Gets the element at the specified index in the read-only list.
public T this[int index] { get; }
Parameters
indexintThe zero-based index of the element to get.
Property Value
- T
The element at the specified index in the read-only list.
NextCursor
次の結果を取得するためのカーソル。蓄えた余剰分を飛び越えた位置を指します(remarks 参照)。
public string? NextCursor { get; }
Property Value
PreviousCursor
前の結果を取得するためのカーソル。
public string? PreviousCursor { get; }
Property Value
Token
NextCursor の別名。
public string? Token { get; }
Property Value
Methods
Empty()
空の結果。
public static Result<T> Empty()
Returns
- Result<T>
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
An enumerator that can be used to iterate through the collection.
NextAsync()
次の結果。蓄えた余剰分があればそれを先に返し、無ければ次のページを取得します。
public Task<Result<T>> NextAsync()
Returns
PreviousAsync()
前の結果。
public Task<Result<T>> PreviousAsync()
Returns
ToList()
この結果のスナップショットをリストとして返します。
public List<T> ToList()
Returns
- List<T>
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.