link providers

This commit is contained in:
2021-02-10 14:53:56 +01:00
parent 0a1ae40ff4
commit 6dce5c3599
18 changed files with 401 additions and 215 deletions
@@ -0,0 +1,26 @@
using System.Collections.Generic;
namespace zero.Core.Extensions
{
public static class DictionaryExtensions
{
public static bool TryGetValue<T>(this Dictionary<string, object> model, string key, out T value)
{
if (!model.TryGetValue(key, out object valueObj) || !(valueObj is T))
{
value = default;
return false;
}
value = (T)valueObj;
return true;
}
public static T GetValueOrDefault<T>(this Dictionary<string, object> model, string key)
{
object? value = model.GetValueOrDefault(key);
return value == default || !(value is T) ? default : (T)value;
}
}
}