using System; using System.Collections.Generic; namespace Mhf.Server.Web { public class WebCollection { private Dictionary _collection; private Func _keyTransformer; public WebCollection() : this(null) { } public WebCollection(Func keyTransformer) { _collection = new Dictionary(); _keyTransformer = keyTransformer; } public ICollection Keys => _collection.Keys; public void Add(TKey key, TValue value) { if (_keyTransformer != null) { key = _keyTransformer(key); } _collection.Add(key, value); } public TValue Get(TKey key) { if (_collection.TryGetValue(key, out TValue value)) { return value; } return default(TValue); } public bool ContainsKey(TKey key) { return _collection.ContainsKey(key); } public TValue this[TKey key] { get => _collection[key]; set => _collection[key] = value; } } }