-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ShellNavigationQueryParameters.cs
110 lines (88 loc) · 2.57 KB
/
ShellNavigationQueryParameters.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace Microsoft.Maui.Controls
{
public class ShellNavigationQueryParameters : IDictionary<string, object>
{
Dictionary<string, object> _internal = new Dictionary<string, object>();
bool _isReadonly;
public ShellNavigationQueryParameters()
{
}
public ShellNavigationQueryParameters(IEnumerable<KeyValuePair<string, object>> collection)
{
foreach (var item in collection)
this.Add(item.Key, item.Value);
}
public ShellNavigationQueryParameters(IDictionary<string, object> dictionary)
{
foreach (var item in dictionary)
this.Add(item.Key, item.Value);
}
internal ShellNavigationQueryParameters SetToReadOnly()
{
_isReadonly = true;
return this;
}
void CheckReadOnlyState()
{
if (_isReadonly)
throw new InvalidOperationException($"ShellNavigationQueryParameters are ReadOnly");
}
public object this[string key]
{
get => _internal[key];
set
{
CheckReadOnlyState();
_internal[key] = value;
}
}
public ICollection<string> Keys => _internal.Keys;
public ICollection<object> Values => _internal.Values;
public int Count => _internal.Count;
public bool IsReadOnly => _isReadonly;
public void Add(string key, object value)
{
CheckReadOnlyState();
_internal.Add(key, value);
}
public void Add(KeyValuePair<string, object> item)
{
CheckReadOnlyState();
_internal.Add(item.Key, item.Value);
}
public void Clear()
{
CheckReadOnlyState();
_internal.Clear();
}
public bool Contains(KeyValuePair<string, object> item) => _internal.ContainsKey(item.Key);
public bool ContainsKey(string key) => _internal.ContainsKey(key);
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
=> (_internal as ICollection<KeyValuePair<string, object>>)?.CopyTo(array, arrayIndex);
public IEnumerator<KeyValuePair<string, object>> GetEnumerator() => _internal.GetEnumerator();
public bool Remove(string key)
{
CheckReadOnlyState();
return _internal.Remove(key);
}
public bool Remove(KeyValuePair<string, object> item)
{
CheckReadOnlyState();
return (_internal as ICollection<KeyValuePair<string, object>>).Remove(item);
}
#if NETSTANDARD2_1 || NETSTANDARD2_0
public bool TryGetValue(string key, out object value)
#else
public bool TryGetValue(string key, [MaybeNullWhen(false)] out object value)
#endif
{
return _internal.TryGetValue(key, out value);
}
IEnumerator IEnumerable.GetEnumerator() =>
_internal.GetEnumerator();
}
}