Files
predavanja/Events-WebApi/Events.WebAPI/Util/Extensions/DictionaryExtensions.cs
2026-05-10 23:39:55 +02:00

21 lines
403 B
C#

namespace Events.WebAPI.Util.Extensions;
public static class DictionaryExtensions
{
public static TValue GetOrCreate<TKey, TValue>(this Dictionary<TKey, TValue> 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];
}
}
}