source:
addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/DictionaryExtensions.cs
@
16173
Last change on this file since 16173 was 8744, checked in by epitzer, 12 years ago | |
---|---|
File size: 837 bytes |
Line | |
---|---|
1 | using System; |
2 | using System.Collections.Generic; |
3 | using System.Linq; |
4 | using System.Text; |
5 | |
6 | namespace HeuristicLab.Analysis.FitnessLandscape { |
7 | public static class DictionaryExtensions { |
8 | public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> d, TKey key, Func<TValue> provider) { |
9 | var value = provider(); |
10 | d.TryGetValue(key, out value); |
11 | return value; |
12 | } |
13 | public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> d, TKey key, TValue def) { |
14 | var value = def; |
15 | d.TryGetValue(key, out value); |
16 | return value; |
17 | } |
18 | public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> d, TKey key) { |
19 | var value = default(TValue); |
20 | d.TryGetValue(key, out value); |
21 | return value; |
22 | } |
23 | } |
24 | } |
Note: See TracBrowser
for help on using the repository browser.