forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupingHandler.cs
More file actions
26 lines (22 loc) · 866 Bytes
/
GroupingHandler.cs
File metadata and controls
26 lines (22 loc) · 866 Bytes
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Simple.Data.QueryPolyfills
{
using Extensions;
class GroupingHandler
{
private readonly HashSet<string> _groupColumns;
public GroupingHandler(params string[] groupColumns)
{
_groupColumns = new HashSet<string>(groupColumns);
}
public IEnumerable<IGrouping<IDictionary<string, object>, IDictionary<string, object>>> Group(IEnumerable<IDictionary<string,object>> source)
{
return source.GroupBy(d => d.Where(kvp => _groupColumns.Contains(kvp.Key)).ToDictionary(),
d => d.Where(kvp => !_groupColumns.Contains(kvp.Key)).ToDictionary(),
new DictionaryEqualityComparer());
}
}
}