using Newtonsoft.Json.Linq; namespace System.Collections.Generic; public static class DictionaryExtensions { public static T GetOrAddCustomConfiguration(this IDictionary customConfiguration, string key) where T : new() { if (customConfiguration.TryGetValue(key, out var config)) { if (config is T typedConfig) return typedConfig; if (config is JToken jToken) return jToken.ToObject(); } var newInstance = new T(); customConfiguration[key] = newInstance; return newInstance; } public static void Deconstruct(this KeyValuePair pair, out TKey key, out TValue value) { key = pair.Key; value = pair.Value; } }