-
Notifications
You must be signed in to change notification settings - Fork 533
Expand file tree
/
Copy pathCosmosObject.EagerCosmosObject.cs
More file actions
66 lines (53 loc) · 2.49 KB
/
CosmosObject.EagerCosmosObject.cs
File metadata and controls
66 lines (53 loc) · 2.49 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
59
60
61
62
63
64
65
66
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.CosmosElements
{
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Cosmos.Json;
#if INTERNAL
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#pragma warning disable SA1601 // Partial elements should be documented
public
#else
internal
#endif
abstract partial class CosmosObject : CosmosElement, IReadOnlyDictionary<string, CosmosElement>, IEquatable<CosmosObject>, IComparable<CosmosObject>
{
private sealed class EagerCosmosObject : CosmosObject
{
private readonly Dictionary<string, CosmosElement> dictionary;
public EagerCosmosObject(IReadOnlyDictionary<string, CosmosElement> dictionary)
{
this.dictionary = new Dictionary<string, CosmosElement>(dictionary.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
}
public override CosmosElement this[string key] => this.dictionary[key];
public override int Count => this.dictionary.Count;
public override KeyCollection Keys => new KeyCollection(this.dictionary.Keys);
public override ValueCollection Values => new ValueCollection(this.dictionary.Values);
public override bool ContainsKey(string key) => this.dictionary.ContainsKey(key);
public override Enumerator GetEnumerator() => new Enumerator(this.dictionary.GetEnumerator());
public override bool TryGetValue(string key, out CosmosElement value) => this.dictionary.TryGetValue(key, out value);
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteObjectStart();
foreach (KeyValuePair<string, CosmosElement> kvp in this.dictionary)
{
if (kvp.Value is not CosmosUndefined)
{
jsonWriter.WriteFieldName(kvp.Key);
kvp.Value.WriteTo(jsonWriter);
}
}
jsonWriter.WriteObjectEnd();
}
}
}
#if INTERNAL
#pragma warning restore SA1601 // Partial elements should be documented
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
#endif
}