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)
throw new ArgumentNullException("value");
// Prevent building a 2-to-1 mapping
if (ContainsKey(key) ^ ContainsValue(value))
throw new InvalidOperationException(
"Can not set key and value when either key or value are already present in the collection");
RemoveKey(key);
RemoveValue(value);
m_KeyToValue[key] = value;
m_ValueToKey[value] = key;
Add(key, value);
}
public TKey GetKey(TValue value)