using System.Collections.Generic; namespace Extensions; public static class Extensions { public static V GetOrCreate(this Dictionary dict, K key) where V : new() where K: notnull { if (!dict.TryGetValue(key, out V? value)) { value = new V(); dict[key] = value; } return value; } }