I have an IList<SomeObject>
where SomeObject
has properties for Date
(DateTime
) and SomeEnum. I've been trying, first with extension functions then with for loops to group first day, they by the value of the enum. I need the output as SomeObjectGroup
objects, where the groups have properties for Date, the enum value and a List<SOmeObject>
of things on that day.
The final variable needs a signature of IDictionary<DateTime, IList<SomeObjectGroup>>
(the time part of DateTime
isn't used), but I'm tearing my hair out with this. Nested loops always get complicated quickly which is why I wanted to use lambda functions, but I just need ot to work (albeit if in a series of steps).
So to clarify (in as simpler sense possible):
From IList<SomeObject>
to:
IDictionary<DateTime, IList<SomeObjectGroup>> x = {
"2009-10-10", enumGroups = {
SomeObjectGroupA {
Date = "2009-10-10",
TheType = BlahEnum.TheFirst,
Items = {
SomeObject1,
SomeObject2,
...,
},
SomeObjectGroupB {
Date = "2009-10-10",
TheType = BlahEnum.TheSecond,
Items = {
SomeObject3,
SomeObject4,
...,
},
... group for the rest of the enum values (if present on this day of the original list)
"2009-10-11", enumGroups = {
SomeObjectGroupA {
Date = "2009-10-11",
TheType = BlahEnum.TheFirst,
Items = {
SomeObject5,
SomeObject6,
...,
},
SomeObjectGroupB {
Date = "2009-10-11",
TheType = BlahEnum.TheSecond,
Items = {
SomeObject7,
SomeObject8,
...,
},
}
Anyone fancy a stab?
}