namespace Events.WebAPI.Util.Extensions; public static class DictionaryExtensions { public static TValue GetOrCreate(this Dictionary dict, TKey key) where TValue : new() where TKey : notnull { if (!dict.ContainsKey(key)) { var item = new TValue(); dict[key] = item; return item; } else { return dict[key]; } } }