/* Copyright (C) 2012-2020 Tal Aloni . All rights reserved. * * You can redistribute this program and/or modify it under the terms of * the GNU Lesser Public License as published by the Free Software Foundation, * either version 3 of the License, or (at your option) any later version. */ using System.Collections.Generic; namespace Utilities { public partial class KeyValuePairList : List> { public KeyValuePairList() { } public KeyValuePairList(List> collection) : base(collection) { } public bool ContainsKey(TKey key) { return (this.IndexOfKey(key) != -1); } public int IndexOfKey(TKey key) { for (int index = 0; index < this.Count; index++) { if (this[index].Key.Equals(key)) { return index; } } return -1; } public TValue ValueOf(TKey key) { for (int index = 0; index < this.Count; index++) { if (this[index].Key.Equals(key)) { return this[index].Value; } } return default(TValue); } public void Add(TKey key, TValue value) { this.Add(new KeyValuePair(key, value)); } public List Keys { get { List result = new List(); foreach (KeyValuePair entity in this) { result.Add(entity.Key); } return result; } } public List Values { get { List result = new List(); foreach (KeyValuePair entity in this) { result.Add(entity.Value); } return result; } } public new KeyValuePairList GetRange(int index, int count) { return new KeyValuePairList(base.GetRange(index, count)); } } }