-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollection.cs
More file actions
58 lines (45 loc) · 2.02 KB
/
Copy pathCollection.cs
File metadata and controls
58 lines (45 loc) · 2.02 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace JSONstat.Models;
/// <summary>
/// A JSON-stat collection response: a set of referenced or embedded items.
/// Source: <c>../wiki/response-classes.md</c>.
/// </summary>
public sealed class Collection
{
/// <summary>JSON-stat version.</summary>
public string? Version { get; set; } = "2.0";
/// <summary>The response class (always <see cref="ResponseClass.Collection"/>).</summary>
public ResponseClass Class { get; set; } = ResponseClass.Collection;
/// <summary>URL of the collection.</summary>
public string? Href { get; set; }
/// <summary>Short descriptive text.</summary>
public string? Label { get; set; }
/// <summary>Update time (ISO 8601).</summary>
public string? Updated { get; set; }
/// <summary>The link relations; <see cref="Link.Item"/> lists the collection items.</summary>
public Link? Link { get; set; }
/// <summary>Provider-specific extension.</summary>
public JsonElement? Extension { get; set; }
/// <summary>Provider-specific extension properties not modelled explicitly.</summary>
[JsonExtensionData]
public IDictionary<string, JsonElement>? ExtensionData { get; set; }
/// <summary>Embedded datasets found in <c>link.item</c> (populated on parse).</summary>
[JsonIgnore]
internal List<Dataset> EmbeddedDatasets { get; } = new List<Dataset>();
/// <summary>The collection items.</summary>
[JsonIgnore]
public IReadOnlyList<LinkItem> Items => Link?.Item ?? Array.Empty<LinkItem>();
/// <summary>Gets the item at <paramref name="index"/>, or <c>null</c>.</summary>
public LinkItem? Item(int index)
{
var items = Items;
return index >= 0 && index < items.Count ? items[index] : null;
}
/// <summary>Gets the items of a given class.</summary>
public IReadOnlyList<LinkItem> ItemsOf(ResponseClass filter) =>
Items.Where(i => i.Class == filter).ToArray();
}