// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; using System.Collections.Generic; namespace Microsoft.AspNetCore.Connections { public class ConnectionItems : IDictionary { public ConnectionItems() : this(new Dictionary()) { } public ConnectionItems(IDictionary items) { Items = items; } public IDictionary Items { get; } // Replace the indexer with one that returns null for missing values object IDictionary.this[object key] { get { if (Items.TryGetValue(key, out var value)) { return value; } return null; } set { Items[key] = value; } } void IDictionary.Add(object key, object value) { Items.Add(key, value); } bool IDictionary.ContainsKey(object key) { return Items.ContainsKey(key); } ICollection IDictionary.Keys { get { return Items.Keys; } } bool IDictionary.Remove(object key) { return Items.Remove(key); } bool IDictionary.TryGetValue(object key, out object value) { return Items.TryGetValue(key, out value); } ICollection IDictionary.Values { get { return Items.Values; } } void ICollection>.Add(KeyValuePair item) { Items.Add(item); } void ICollection>.Clear() { Items.Clear(); } bool ICollection>.Contains(KeyValuePair item) { return Items.Contains(item); } void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) { Items.CopyTo(array, arrayIndex); } int ICollection>.Count { get { return Items.Count; } } bool ICollection>.IsReadOnly { get { return Items.IsReadOnly; } } bool ICollection>.Remove(KeyValuePair item) { if (Items.TryGetValue(item.Key, out var value) && Equals(item.Value, value)) { return Items.Remove(item.Key); } return false; } IEnumerator> IEnumerable>.GetEnumerator() { return Items.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return Items.GetEnumerator(); } } }