forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectValueResolver.cs
More file actions
32 lines (28 loc) · 1.22 KB
/
ObjectValueResolver.cs
File metadata and controls
32 lines (28 loc) · 1.22 KB
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
using System.Collections.Generic;
namespace Simple.Data.QueryPolyfills
{
class ObjectValueResolver : ValueResolver
{
private readonly ObjectReference _reference;
protected internal ObjectValueResolver(ObjectReference reference)
{
_reference = reference;
}
public override void CopyValue(IDictionary<string, object> source, IDictionary<string, object> target,
IEnumerable<IDictionary<string, object>> sourceAggregationValues = null)
{
target[_reference.GetAliasOrName()] = GetValue(source);
}
public override object GetValue(IDictionary<string, object> source, IEnumerable<IDictionary<string, object>> sourceAggregationValues = null)
{
if (source == null) return null;
if (_reference.HasOwner() && source.ContainsKey(_reference.GetOwner().GetName()))
{
var childDictionary = source[_reference.GetOwner().GetName()] as IDictionary<string, object>;
return GetValue(childDictionary);
}
if (source.ContainsKey(_reference.GetName())) return source[_reference.GetName()];
return null;
}
}
}