Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CollectionExtensions.cs
Go to the documentation of this file.
2
4
5public static class CollectionExtensions
6{
8 {
9 return dictionary.GetValueOrDefault(key, default(TValue));
10 }
11
13 {
14 if (dictionary == null)
15 {
16 throw new ArgumentNullException("dictionary");
17 }
18 if (!dictionary.TryGetValue(key, out TValue value))
19 {
20 return defaultValue;
21 }
22 return value;
23 }
24
25 public static bool TryAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
26 {
27 if (dictionary == null)
28 {
29 throw new ArgumentNullException("dictionary");
30 }
31 if (!dictionary.ContainsKey(key))
32 {
33 dictionary.Add(key, value);
34 return true;
35 }
36 return false;
37 }
38
39 public static bool Remove<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, [MaybeNullWhen(false)] out TValue value)
40 {
41 if (dictionary == null)
42 {
43 throw new ArgumentNullException("dictionary");
44 }
45 if (dictionary.TryGetValue(key, out value))
46 {
47 dictionary.Remove(key);
48 return true;
49 }
50 value = default(TValue);
51 return false;
52 }
53}
static bool Remove< TKey, TValue >(this IDictionary< TKey, TValue > dictionary, TKey key, [MaybeNullWhen(false)] out TValue value)
static bool TryAdd< TKey, TValue >(this IDictionary< TKey, TValue > dictionary, TKey key, TValue value)
static ? TValue GetValueOrDefault< TKey, TValue >(this IReadOnlyDictionary< TKey, TValue > dictionary, TKey key)