Ui-Info-Suite/SDVModTest/Extensions/CollectionExtensions.cs

26 lines
632 B
C#
Raw Permalink Normal View History

2017-07-20 11:51:05 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UIInfoSuite.Extensions
{
static class CollectionExtensions
{
public static TValue SafeGet<Tkey, TValue>(this IDictionary<Tkey, TValue> dictionary, Tkey key, TValue defaultValue = default(TValue))
{
TValue value = defaultValue;
if (dictionary != null)
{
if (!dictionary.TryGetValue(key, out value))
value = defaultValue;
}
return value;
}
}
}