public static class CollectionExtensions { public static TValue GetOrAddNew( this Dictionary dict, TKey key) where TValue : new() { if (!dict.TryGetValue(key, out var value)) dict.Add(key, value = new()); return value; } }