BITKit/Packages/Core/Extensions/IDictionary.cs

21 lines
552 B
C#

using Newtonsoft.Json.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BITKit
{
public static partial class Extensions
{
public static IDictionary<TKey, TValue> CreateOrAddIfEmety<TKey, TValue>(this IDictionary<TKey, TValue> self, TKey key, Func<TValue> createFactory)
{
if (self.ContainsKey(key) is false)
{
self.Add(key, createFactory.Invoke());
}
return self;
}
}
}