Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DictionaryExtensions.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Collections.Generic;
4 
5 namespace SiliconStudio.Core.Extensions
6 {
7  public static class DictionaryExtensions
8  {
9  public static bool TryGetValueCast<TKey, TValue, TResult>(this IDictionary<TKey, TValue> dictionary, TKey key, out TResult result)
10  where TResult : TValue
11  {
12  TValue value;
13  if (dictionary.TryGetValue(key, out value))
14  {
15  result = (TResult)value;
16  return true;
17  }
18 
19  result = default(TResult);
20  return false;
21  }
22 
23  public static TValue TryGetValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
24  {
25  TValue value;
26  dictionary.TryGetValue(key, out value);
27  return value;
28  }
29  }
30 }