/
DictionaryKeyValues.cs
60 lines (48 loc) · 1.34 KB
/
DictionaryKeyValues.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
namespace FubuCore.Util
{
public class DictionaryKeyValues<T> : IKeyValues<T>
{
private readonly IDictionary<string, T> _dictionary;
public DictionaryKeyValues()
: this(new Dictionary<string, T>())
{
}
public DictionaryKeyValues(IDictionary<string, T> dictionary)
{
_dictionary = dictionary;
}
public IDictionary<string, T> Dictionary
{
get { return _dictionary; }
}
public bool Has(string key)
{
return _dictionary.ContainsKey(key);
}
public T Get(string key)
{
return _dictionary[key];
}
public IEnumerable<string> GetKeys()
{
return _dictionary.Keys;
}
public bool ForValue(string key, Action<string, T> callback)
{
if (!Has(key)) return false;
callback(key, Get(key));
return true;
}
}
public class DictionaryKeyValues : DictionaryKeyValues<string>, IKeyValues
{
public DictionaryKeyValues()
{
}
public DictionaryKeyValues(IDictionary<string, string> dictionary) : base(dictionary)
{
}
}
}