using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; namespace ScreenConnect; public class OrderedDictionary : IOrderedDictionary, IDictionary, ICollection>, IEnumerable>, IEnumerable { private OrderedDictionary backingDictionary; public int Count => backingDictionary.Count; public bool IsReadOnly => backingDictionary.IsReadOnly; public TValue this[int index] { get { return (TValue)backingDictionary[index]; } set { backingDictionary[index] = value; } } public TValue this[TKey key] { get { return (TValue)backingDictionary[key]; } set { backingDictionary[key] = value; } } public ICollection Keys => (from _ in GetKeyValuePairs() select _.Key).ToList(); public ICollection Values => (from _ in GetKeyValuePairs() select _.Value).ToList(); public OrderedDictionary() { backingDictionary = new OrderedDictionary(); } public OrderedDictionary(int count) { backingDictionary = new OrderedDictionary(count); } private IEnumerable> GetKeyValuePairs() { return from _ in backingDictionary.OfType() select Extensions.CreateKeyValuePair((TKey)_.Key, (TValue)_.Value); } public void Add(TKey key, TValue value) { backingDictionary.Add(key, value); } public void Add(KeyValuePair item) { Add(item.Key, item.Value); } public void Clear() { backingDictionary.Clear(); } public bool Contains(KeyValuePair item) { if (ContainsKey(item.Key)) { return object.Equals(this[item.Key], item.Value); } return false; } public bool ContainsKey(TKey key) { return backingDictionary.Contains(key); } public void CopyTo(KeyValuePair[] array, int arrayIndex) { GetKeyValuePairs().ToList().CopyTo(array, arrayIndex); } public IEnumerator> GetEnumerator() { return GetKeyValuePairs().GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void Insert(int index, TKey key, TValue value) { backingDictionary.Insert(index, key, value); } public bool Remove(TKey key) { if (!ContainsKey(key)) { return false; } backingDictionary.Remove(key); return true; } public bool Remove(KeyValuePair item) { return Remove(item.Key); } public void RemoveAt(int index) { backingDictionary.RemoveAt(index); } public bool TryGetValue(TKey key, out TValue value) { if (!ContainsKey(key)) { value = default(TValue); return false; } value = this[key]; return true; } }