public new void Remove(TKey item) { TValue value = this[item]; base.Remove(item); ReverseDictionary.Remove(value); }
private void OnDeserialized(StreamingContext context) { this.secondToFirst = new Dictionary <TSecond, TFirst>(firstToSecond.Count); foreach (var item in firstToSecond) { secondToFirst.Add(item.Value, item.Key); } reverse = new ReverseDictionary(this); }
public new void Add(TKey value1, TValue value2) { if (ReverseDictionary.ContainsKey(value2)) { throw new ArgumentException("已经有相同的值了"); } base.Add(value1, value2); ReverseDictionary.Add(value2, value1); }
/// <summary> /// Initializes a new instance of the <see cref="TwoWayDictionary{TFirst, TSecond}"/> class /// that contains elements copied from the specified dictionary and uses the default equality /// comparer for the key type. /// </summary> /// /// <param name="dictionary">The dictionary whose elements are copied to the new <see cref="TwoWayDictionary{TFirst, TSecond}"/>.</param> /// public TwoWayDictionary(IDictionary <TFirst, TSecond> dictionary) { firstToSecond = new Dictionary <TFirst, TSecond>(dictionary); secondToFirst = new Dictionary <TSecond, TFirst>(); foreach (var value in dictionary) { secondToFirst.Add(value.Value, value.Key); } reverse = new ReverseDictionary(this); }
private void OnDeserialized(StreamingContext context) { // Force complete deserialization of the first-to-second dictionary (this.firstToSecond as IDeserializationCallback).OnDeserialization(this); this.secondToFirst = new Dictionary <TSecond, TFirst>(firstToSecond.Count); foreach (var item in firstToSecond) { secondToFirst.Add(item.Value, item.Key); } reverse = new ReverseDictionary(this); }
protected BiDictionary(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException(nameof(info)); } var data = (byte[])info.GetValue("firstToSecond", typeof(byte[])); using (var memoryStream = new MemoryStream(data)) { var binaryFormatter = new BinaryFormatter(); _firstToSecond = (Dictionary <TFirst, TSecond>)binaryFormatter.Deserialize(memoryStream); } _secondToFirst = new Dictionary <TSecond, TFirst>(); _reverseDictionary = new ReverseDictionary(this); }
/// <summary> /// Initializes a new instance of the <see cref="TwoWayDictionary{TFirst, TSecond}"/> class /// that is empty, has the specified initial capacity, and uses the default equality comparer /// for the key type. /// </summary> /// /// <param name="capacity">The initial number of elements that this dictionary can contain.</param> /// public TwoWayDictionary(int capacity) { firstToSecond = new Dictionary <TFirst, TSecond>(capacity); secondToFirst = new Dictionary <TSecond, TFirst>(capacity); reverse = new ReverseDictionary(this); }
public BiDictionary() { _reverseDictionary = new ReverseDictionary(this); }
/// <summary> /// Initializes a new instance of the <see cref="TwoWayDictionary{TFirst, TSecond}"/> class /// that is empty, has the default initial capacity, and uses the default equality comparer /// for the key type. /// </summary> /// public TwoWayDictionary() { this.firstToSecond = new Dictionary <TFirst, TSecond>(); this.secondToFirst = new Dictionary <TSecond, TFirst>(); this.reverse = new ReverseDictionary(this); }
public BiDictionary() { _secondToFirst = new Dictionary <TSecond, TFirst>(); _reverseDictionary = new ReverseDictionary(this); }
public TwoWayDictionary() { _reverseDictionary = new ReverseDictionary(this); }
public new bool ContainsValue(TValue value) { return(ReverseDictionary.ContainsKey(value)); }