-
-
Notifications
You must be signed in to change notification settings - Fork 723
/
ArgumentMap.cs
61 lines (44 loc) · 1.64 KB
/
ArgumentMap.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
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using HotChocolate.Resolvers;
#nullable enable
namespace HotChocolate.Execution.Processing;
internal sealed class ArgumentMap : IArgumentMap
{
private readonly IReadOnlyDictionary<string, ArgumentValue> _arguments;
private readonly bool _isFinal;
private readonly bool _hasErrors;
public ArgumentMap(IReadOnlyDictionary<string, ArgumentValue> arguments)
{
_arguments = arguments;
_isFinal = true;
if (_arguments.Count > 0)
{
foreach (var argument in arguments.Values)
{
if (!argument.IsFullyCoerced)
{
_isFinal = false;
}
if (argument.HasError)
{
_hasErrors = true;
}
}
}
}
public ArgumentValue this[string key] => _arguments[key];
public bool IsFinalNoErrors => _isFinal && !_hasErrors;
public bool IsFinal => _isFinal;
public bool HasErrors => _hasErrors;
public IEnumerable<string> Keys => _arguments.Keys;
public IEnumerable<ArgumentValue> Values => _arguments.Values;
public int Count => _arguments.Count;
public bool ContainsKey(string key) => _arguments.ContainsKey(key);
public bool TryGetValue(string key, [MaybeNullWhen(false)] out ArgumentValue value)
=> _arguments.TryGetValue(key, out value);
public IEnumerator<KeyValuePair<string, ArgumentValue>> GetEnumerator()
=> _arguments.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}