/// <summary> /// Add a key / value pair to the dictionary. /// </summary> /// <param name="item"> /// The <see cref="KeyValuePair{TKey, TValue}"/> to add. /// </param> public void Add(KeyValuePair <T3, T4> item) { if (item.Key == null) { throw new ArgumentException("Key cannot be null.", nameof(item)); } if (item.Value == null) { throw new ArgumentException("Value cannot be null.", nameof(item)); } if (ForwardLookup.ContainsKey(item.Key)) { throw new ArgumentException("The dictionary's forward-lookup section already contains the specified key.", nameof(item)); } if (ReverseLookup.ContainsKey(item.Value)) { throw new ArgumentException("The dictionary's reverse-lookup section already contains the specified key.", nameof(item)); } ForwardLookup.Add(item.Key, item.Value); ReverseLookup.Add(item.Value, item.Key); }
/// <summary> /// Add a value to the dictionary with the specified key. /// </summary> /// <param name="key"> /// The key. /// </param> /// <param name="value"> /// The value. /// </param> public void Add(T3 key, T4 value) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } if (ForwardLookup.ContainsKey(key)) { throw new ArgumentException("The dictionary's forward-lookup section already contains the specified key.", nameof(key)); } if (ReverseLookup.ContainsKey(value)) { throw new ArgumentException("The dictionary's reverse-lookup section already contains the specified key.", nameof(value)); } ForwardLookup.Add(key, value); ReverseLookup.Add(value, key); }
/// <summary> /// Attempt to remove a key / value pair from the dictionary. /// </summary> /// <param name="item"> /// The key / value pair to remove. /// </param> /// <returns> /// <c>true</c>, if the key / value pair was removed; otherwise, <c>false</c>. /// </returns> public bool Remove(KeyValuePair <T3, T4> item) { if (!ForwardLookup.Remove(item)) { return(false); } ReverseLookup.Remove(new KeyValuePair <T4, T3>( key: item.Value, value: item.Key )); return(true); }
/// <summary> /// Attempt to remove a value from the dictionary. /// </summary> /// <param name="key"> /// The key of the value to remove. /// </param> /// <returns> /// <c>true</c>, if the value was removed; otherwise, <c>false</c>. /// </returns> public bool Remove(T3 key) { T4 value; if (!ForwardLookup.TryGetValue(key, out value)) { return(false); } ForwardLookup.Remove(key); ReverseLookup.Remove(value); return(true); }
/// <summary> /// Attempt to retrieve the value with the specified key. /// </summary> /// <param name="key"> /// The key. /// </param> /// <param name="value"> /// Receives the value. /// </param> /// <returns> /// <c>true</c>, if the value pair retrieved; otherwise, <c>false</c>. /// </returns> public bool TryGetValue(T3 key, out T4 value) => ForwardLookup.TryGetValue(key, out value);
/// <summary> /// Retrieve a typed enumerator for all key / value pairs in the dictionary. /// </summary> /// <returns> /// The typed enumerator. /// </returns> public IEnumerator <KeyValuePair <T3, T4> > GetEnumerator() => ForwardLookup.GetEnumerator();
/// <summary> /// Copy the dictionary contents to the specified array. /// </summary> /// <param name="array"> /// The target array of <see cref="KeyValuePair{TKey, TValue}"/>s. /// </param> /// <param name="arrayIndex"> /// The target index at which to start placing copied items. /// </param> public void CopyTo(KeyValuePair <T3, T4>[] array, int arrayIndex) => ForwardLookup.CopyTo(array, arrayIndex);
/// <summary> /// Determine whether the dictionary contains the specified key. /// </summary> /// <param name="key"> /// The key. /// </param> /// <returns> /// <c>true</c>, if the dictionary contains the key; otherwise, <c>false</c>. /// </returns> public bool ContainsKey(T3 key) => ForwardLookup.ContainsKey(key);
/// <summary> /// Determine whether the dictionary contains the specified key / value pair. /// </summary> /// <param name="item"> /// The key / value pair to search for. /// </param> /// <returns> /// <c>true</c>, if the dictionary contains the key and corresponding value; otherwise, <c>false</c>. /// </returns> public bool Contains(KeyValuePair <T3, T4> item) => ForwardLookup.Contains(item);
/// <summary> /// Remove all keys and values from the dictionary. /// </summary> public void Clear() { ForwardLookup.Clear(); ReverseLookup.Clear(); }