fix: Better set key/value behaviour for BiDictionary

This commit is contained in:
Chris Cameron
2018-06-11 17:04:26 -04:00
parent 8d683f875b
commit 2fab5d6fd4

View File

@@ -83,13 +83,10 @@ namespace ICD.Common.Utils.Collections
if (value == null) if (value == null)
throw new ArgumentNullException("value"); throw new ArgumentNullException("value");
// Prevent building a 2-to-1 mapping RemoveKey(key);
if (ContainsKey(key) ^ ContainsValue(value)) RemoveValue(value);
throw new InvalidOperationException(
"Can not set key and value when either key or value are already present in the collection");
m_KeyToValue[key] = value; Add(key, value);
m_ValueToKey[value] = key;
} }
public TKey GetKey(TValue value) public TKey GetKey(TValue value)