using Kit.Helpers.Log; using System.Collections; using System.Collections.Generic; namespace Kit.Helpers.Repository { public interface ISelectContext : IDictionaryCacheProvider { #if NETCOREAPP IDictionary Items { get; } #elif NETFRAMEWORK IDictionary Items { get; } #endif ICallStackLog CallStackLog { get; set; } } public class SelectContext : ISelectContext { public SelectContext() { Items = new Dictionary(); CallStackLog = Log.CallStackLog.Empty; } #if NETCOREAPP public IDictionary Items { get; } #elif NETFRAMEWORK public IDictionary Items { get; } #endif public ICallStackLog CallStackLog { get; set; } private Dictionary GetOrCreateDictionary(string cacheKey) { #if NETCOREAPP Dictionary cacheDictionary = Items.ContainsKey(cacheKey) ? (Dictionary)Items[cacheKey] : null; #elif NETFRAMEWORK Dictionary cacheDictionary = Items.Contains(cacheKey) ? (Dictionary)Items[cacheKey] : null; #endif if (cacheDictionary == null) { cacheDictionary = new Dictionary(); Items[cacheKey] = cacheDictionary; } return cacheDictionary; } public void SetByKey(string cacheKey, TKey key, TValue value) => GetOrCreateDictionary(cacheKey).SetByKey(key, value); public TValue GetByKey(string cacheKey, TKey key) => GetOrCreateDictionary(cacheKey).GetByKey(key); public TValue GetByKey(string cacheKey, TKey key, TValue defaultValue) => GetOrCreateDictionary(cacheKey).GetByKey(key, defaultValue); public bool TryGet(string cacheKey, TKey key, TValue defaultValue, out TValue value) { throw new System.NotImplementedException(); } } }