Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/DictionaryExtensions.cs @ 16995

Last change on this file since 16995 was 16995, checked in by gkronber, 5 years ago

#2520 Update plugin dependencies and references for HL.FLA for new persistence

File size: 797 bytes
Line 
1using System;
2using System.Collections.Generic;
3
4namespace HeuristicLab.Analysis.FitnessLandscape {
5  public static class DictionaryExtensions {
6    public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> d, TKey key, Func<TValue> provider) {
7      var value = provider();
8      d.TryGetValue(key, out value);
9      return value;
10    }
11    public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> d, TKey key, TValue def) {
12      var value = def;
13      d.TryGetValue(key, out value);
14      return value;
15    }
16    public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> d, TKey key) {
17      var value = default(TValue);
18      d.TryGetValue(key, out value);
19      return value;
20    }
21  }
22}
Note: See TracBrowser for help on using the repository browser.