27 lines
559 B
C#
27 lines
559 B
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Runtime.CompilerServices;
|
|||
|
|
using System.Runtime.InteropServices;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace BS.Shared.Extensions
|
|||
|
|
{
|
|||
|
|
public static class DictionaryExtensions
|
|||
|
|
{
|
|||
|
|
public static T2 GetValueOrDefault<T1, T2>(this Dictionary<T1, T2> dictionary, T1 key, T2 t_default)
|
|||
|
|
{
|
|||
|
|
if (dictionary is null || !dictionary.Any())
|
|||
|
|
return t_default;
|
|||
|
|
|
|||
|
|
if (dictionary.TryGetValue(key, out var val))
|
|||
|
|
{
|
|||
|
|
return val;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return t_default;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|