diff options
| author | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-25 22:43:56 -0500 |
|---|---|---|
| committer | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-25 22:43:56 -0500 |
| commit | efdb2f3990f6a5250949b7a86bbd83def876f612 (patch) | |
| tree | d4c7df1c5f159e5a544ebf0b168f18cb302a7712 /MediaBrowser.Installer/Code/ModelExtensions.cs | |
| parent | 2d06095447b972c8c7239277428e2c67c8b7ca86 (diff) | |
| parent | 59ce9444786c4cb3a4eac23f4d26c537a9983c8f (diff) | |
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Conflicts:
Nuget/MediaBrowser.ApiClient.nuspec
Diffstat (limited to 'MediaBrowser.Installer/Code/ModelExtensions.cs')
| -rw-r--r-- | MediaBrowser.Installer/Code/ModelExtensions.cs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/MediaBrowser.Installer/Code/ModelExtensions.cs b/MediaBrowser.Installer/Code/ModelExtensions.cs index 5a3051164..66e51ec11 100644 --- a/MediaBrowser.Installer/Code/ModelExtensions.cs +++ b/MediaBrowser.Installer/Code/ModelExtensions.cs @@ -1,4 +1,6 @@ +using System.Collections.Generic; + namespace MediaBrowser.Installer.Code { /// <summary> @@ -16,5 +18,26 @@ namespace MediaBrowser.Installer.Code { return string.IsNullOrEmpty(str) ? def : str; } + + /// <summary> + /// Helper method for Dictionaries since they throw on not-found keys + /// </summary> + /// <typeparam name="T"></typeparam> + /// <typeparam name="U"></typeparam> + /// <param name="dictionary">The dictionary.</param> + /// <param name="key">The key.</param> + /// <param name="defaultValue">The default value.</param> + /// <returns>``1.</returns> + public static U GetValueOrDefault<T, U>(this Dictionary<T, U> dictionary, T key, U defaultValue) + { + U val; + if (!dictionary.TryGetValue(key, out val)) + { + val = defaultValue; + } + return val; + + } + } } |
