Was.OrcSearch – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
2 | using System.Collections.Generic; |
||
3 | using Was.OrcSearch.Models.Interfaces; |
||
4 | |||
5 | namespace Was.OrcSearch.Models |
||
6 | { |
||
7 | public class DictionaryMetadata : IMetadata |
||
8 | { |
||
9 | #region Fields |
||
10 | |||
11 | private readonly string _key; |
||
12 | |||
13 | #endregion |
||
14 | |||
15 | #region Constructors |
||
16 | |||
17 | public DictionaryMetadata() |
||
18 | { |
||
19 | } |
||
20 | |||
21 | public DictionaryMetadata(string key, Type expectedType) |
||
22 | : this() |
||
23 | { |
||
24 | _key = key; |
||
25 | DisplayName = key; |
||
26 | Type = expectedType; |
||
27 | } |
||
28 | |||
29 | #endregion |
||
30 | |||
31 | #region Properties |
||
32 | |||
33 | public virtual string DisplayName { get; set; } |
||
34 | |||
35 | public virtual string Name => _key; |
||
36 | |||
37 | public virtual Type Type { get; } |
||
38 | |||
39 | #endregion |
||
40 | |||
41 | #region Methods |
||
42 | |||
43 | public virtual object GetValue(object instance) |
||
44 | { |
||
45 | object result = null; |
||
46 | |||
47 | var dictionary = instance as IDictionary<string, object>; |
||
48 | if (dictionary != null) dictionary.TryGetValue(_key, out result); |
||
49 | |||
50 | return result; |
||
51 | } |
||
52 | |||
53 | public virtual void SetValue(object instance, object value) |
||
54 | { |
||
55 | var dictionary = instance as IDictionary<string, object>; |
||
56 | if (dictionary == null) return; |
||
57 | |||
58 | dictionary[_key] = value; |
||
59 | } |
||
60 | |||
61 | #endregion |
||
62 | } |
||
63 | } |