تخطَّ إلى المستندات
C#

ترقيم الصفحات

صفحة واحدة، أو كل الصفحات، أو عنصر واحد في كل مرة.

صفحة واحدة

page.cs
var page = await client.Threads.ListAsync(folder: "inbox", limit: 25); foreach (var thread in page){    Console.WriteLine(thread["id"]);} if (page.HasMore){    var next = await client.Threads.ListAsync(folder: "inbox", limit: 25, cursor: page.NextCursor);     Console.WriteLine(next.Count);}

دالة ListAsync تعيد Page فيها Items وHasMore وNextCursor، وتتنقل foreach بين عناصرها. مرّر NextCursor من جديد بصفته cursor: مع المرشحات نفسها لقراءة الصفحة التالية.

كل الصفحات

all.cs
var failed = await client.Emails.ListAllAsync(status: new[] { "failed" }); Console.WriteLine($"{failed.Count} messages failed");

دالة ListAllAsync تتبع المؤشر حتى النهاية وتعيد كل العناصر في قائمة واحدة. الإخفاق في أي صفحة يُفشل الاستدعاء كله.

عنصر واحد في كل مرة

iterate.cs
await foreach (var contact in client.Contacts.IterateAsync(limit: 100)){    if ((string?)contact["email"] == "[email protected]")    {        break;    }} await foreach (var entry in client.Emails.IterateEventsAsync("msg_3f9a1c07d2b84e6a9c5b1f20")){    Console.WriteLine(entry["type"]);}

دالة IterateAsync تعيد IAsyncEnumerable<JsonObject>، وهو لا يطلب الصفحة التالية إلا حين تصل إليها الحلقة، لذا توقف break الطلبات. كل قائمة مقسمة إلى صفحات لها الدوال الثلاث، مسماة على اسم القائمة التي تتنقل فيها: ListAllEventsAsync وIterateEventsAsync بجانب ListEventsAsync.

يتوقف التنقل حين تكرر الواجهة البرمجية مؤشرًا سبق أن تبعه، فلا يمكن أن يدور إلى ما لا نهاية.