From 2fab5d6fd4be789d20dfab20b7af85cd672d9b16 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Mon, 11 Jun 2018 17:04:26 -0400 Subject: [PATCH] fix: Better set key/value behaviour for BiDictionary --- ICD.Common.Utils/Collections/BiDictionary.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ICD.Common.Utils/Collections/BiDictionary.cs b/ICD.Common.Utils/Collections/BiDictionary.cs index 21c9d41..d30326a 100644 --- a/ICD.Common.Utils/Collections/BiDictionary.cs +++ b/ICD.Common.Utils/Collections/BiDictionary.cs @@ -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)