summaryrefslogtreecommitdiff
path: root/Plugins/MonoGame.Extended/source/MonoGame.Extended/Collections/DictionaryExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Plugins/MonoGame.Extended/source/MonoGame.Extended/Collections/DictionaryExtensions.cs')
-rw-r--r--Plugins/MonoGame.Extended/source/MonoGame.Extended/Collections/DictionaryExtensions.cs18
1 files changed, 18 insertions, 0 deletions
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended/Collections/DictionaryExtensions.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended/Collections/DictionaryExtensions.cs
new file mode 100644
index 0000000..ee581b7
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended/Collections/DictionaryExtensions.cs
@@ -0,0 +1,18 @@
+using System.Collections.Generic;
+
+namespace MonoGame.Extended.Collections
+{
+ public static class DictionaryExtensions
+ {
+ public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key)
+ {
+ return GetValueOrDefault(dictionary, key, default(TValue));
+ }
+
+ public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
+ {
+ TValue value;
+ return dictionary.TryGetValue(key, out value) ? value : defaultValue;
+ }
+ }
+} \ No newline at end of file