I have list of objects with three keys and I want to convert it to three levels of lookups (or dictionaries):
class MyClass
{
public int Key1;
public int Key2;
public int Key3;
public float Value;
}
...
IEnumerable<MyClass> table = new List<MyClass>()
{
new MyClass(){Key1 = 11, Key2 = 21, Key3 = 31, Value = 1},
new MyClass(){Key1 = 11, Key2 = 21, Key3 = 32, Value = 2},
new MyClass(){Key1 = 11, Key2 = 22, Key3 = 31, Value = 3},
new MyClass(){Key1 = 11, Key2 = 23, Key3 = 33, Value = 4},
new MyClass(){Key1 = 12, Key2 = 21, Key3 = 32, Value = 5},
new MyClass(){Key1 = 12, Key2 = 22, Key3 = 31, Value = 6}
};
I want the result to be of type:
ILookup<int, ILookup<int, Dictionary<int, float>>>
or
Dictionary<int, Dictionary<int, Dictionary<int, float>>>
I tried:
ILookup<int, MyClass> level1 = table.ToLookup(i => i.Key1, i => i);
ILookup<int, ILookup<int, MyClass>> level2 = level1.ToLookup(
i => i.Key, i => i.ToLookup(j => j.Key2, j => j));
ILookup<int, ILookup<int, Dictionary<int, float>>> level3 = ?
, but I'm stucked in third level. It's probably a dupe, but what I'm looking for is probably buried under tons of questions about lists of objects with parent-child relation. [1] [2] [3] [4]