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