18 lines
556 B
C#
18 lines
556 B
C#
|
|
using System.Collections.Generic;
|
||
|
|
|
||
|
|
namespace HC
|
||
|
|
{
|
||
|
|
public static class HCExtensions
|
||
|
|
{
|
||
|
|
public static void AddIfNotExists<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
|
||
|
|
{
|
||
|
|
if (!dictionary.ContainsKey(key))
|
||
|
|
dictionary.Add(key, value);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static TValue GetValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue defalut)
|
||
|
|
{
|
||
|
|
return dictionary.TryGetValue(key, out var value) ? value : defalut;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|