/// <inheritdoc cref="ICloneable.Clone" /> public object Clone() { lock (_syncRoot) { BidirectionalDictionary <TKey, TValue> result = new BidirectionalDictionary <TKey, TValue>(); foreach (KeyValuePair <TKey, TValue> pair in _straight) { result._straight.Add(pair.Key, pair.Value); result._reverse.Add(pair.Value, pair.Key); } return(result); } }
/// <summary> /// Gets read-only shallow copy of the /// <see cref="BidirectionalDictionary{TKey,TValue}"/>. /// </summary> /// <returns>Read-only shallow copy of the dictionary.</returns> public BidirectionalDictionary <TKey, TValue> AsReadOnly() { lock (_syncRoot) { BidirectionalDictionary <TKey, TValue> result = new BidirectionalDictionary <TKey, TValue> { _straight = _straight, _reverse = _reverse, _isReadOnly = true }; return(result); } }