Add a key-value-pair to the multidictionary. If the key is already present, its associated value must satisfy keyComparer.Equals(value, item.Value). Whether the key is entirely new to the dictionary. If it was already present, we assert that the old value is equal to the new value.
(TKey key, TValue value)
| 65 | /// <param name="item"></param> |
| 66 | /// <returns>Whether the key is entirely new to the dictionary. If it was already present, we assert that the old value is equal to the new value.</returns> |
| 67 | public bool Add(TKey key, TValue value) |
| 68 | { |
| 69 | if (value == null) |
| 70 | { |
| 71 | throw new NullReferenceException("Null values are forbidden in multidictionary"); |
| 72 | } |
| 73 | Debug.Assert(RawDict != null); |
| 74 | Debug.Assert(key != null); |
| 75 | if (RawDict.TryGetValue(key, out var result)) |
| 76 | { |
| 77 | Debug.Assert(ValueComparer.Equals(value, result.Value)); |
| 78 | RawDict[key] = (value, result.Multiplicity + 1); |
| 79 | return false; |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | RawDict[key] = (value, 1); |
| 84 | return true; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /// <summary> |
| 89 | /// Completely clear the multidictionary. |
no test coverage detected