PI06 i PI06-1. Docker definitions for MSSQL and Postgres. Data seeder/generator for countries and people. Entity Framework example with variants for Postgres and MSSQL
This commit is contained in:
18
SomeOfCSharpFeatures/Extensions/Extensions.cs
Normal file
18
SomeOfCSharpFeatures/Extensions/Extensions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user