using System; using System.Collections.Generic; namespace Wabbajack { public static class DictionaryExt { public static V TryCreate(this IDictionary dict, K key) where V : new() { return dict.TryCreate(key, () => new V()); } public static V TryCreate(this IDictionary dict, K key, Func create) { if (dict.TryGetValue(key, out var val)) return val; var ret = create(); dict[key] = ret; return ret; } } }