Mercurial > repos > IBBoard
comparison Collections/DictionaryUtils.cs @ 29:e38192f55d2d
* Add convenience method to get a value from a dictionary in a single line
* Commit .csproj file to include XMLTools in project
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 11 Apr 2009 14:47:20 +0000 |
parents | 41ddcd61dc92 |
children |
comparison
equal
deleted
inserted
replaced
28:41ddcd61dc92 | 29:e38192f55d2d |
---|---|
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 return mergedDictionary; | 90 return mergedDictionary; |
91 } | 91 } |
92 | |
93 /// <summary> | |
94 /// Convenience method to get a value from a dictionary for a given key. This method wraps a TryGetValue call in a single function. | |
95 /// </summary> | |
96 /// <param name="dictionary"> | |
97 /// The <see cref="IDictionary"/> to get a value from | |
98 /// </param> | |
99 /// <param name="key"> | |
100 /// The key to get the value for | |
101 /// </param> | |
102 /// <returns> | |
103 /// The value for <code>key</code>, or <code>null</code> if there was no value for the key | |
104 /// </returns> | |
105 public static VALUE_TYPE GetValue<KEY_TYPE, VALUE_TYPE>(IDictionary<KEY_TYPE, VALUE_TYPE> dictionary, KEY_TYPE key) | |
106 { | |
107 if (dictionary == null) | |
108 { | |
109 return default(VALUE_TYPE); | |
110 } | |
111 | |
112 VALUE_TYPE val = default(VALUE_TYPE); | |
113 dictionary.TryGetValue(key, out val); | |
114 return val; | |
115 } | |
92 } | 116 } |
93 } | 117 } |