Last active
December 8, 2016 17:20
-
-
Save jamesmanning/0a6cf6d0ca0546084adf5db657de8d2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Extensions | |
{ | |
public static Dictionary<TKeyOuter, Dictionary<TKeyMiddle, Dictionary<TKeyInner, TValue>>> ToThreeLevelDictionary<TKeyOuter, TKeyMiddle, TKeyInner, TValue, TInput>( | |
this IEnumerable<TInput> input, | |
Func<TInput, TKeyOuter> outerKeySelector, | |
Func<TInput, TKeyMiddle> middleKeySelector, | |
Func<TInput, TKeyInner> innerKeySelector, | |
Func<TInput, TValue> valueSelector) | |
{ | |
return input | |
.ToLookup(outerKeySelector) | |
.ToDictionaryWithDuplicateKeyCheck( | |
x => x.Key, | |
x => x.ToTwoLevelDictionary(middleKeySelector, innerKeySelector, valueSelector)); | |
} | |
public static Dictionary<TKeyOuter, Dictionary<TKeyInner, TValue>> ToTwoLevelDictionary<TKeyOuter, TKeyInner, TValue, TInput>( | |
this IEnumerable<TInput> input, | |
Func<TInput, TKeyOuter> outerKeySelector, | |
Func<TInput, TKeyInner> innerKeySelector, | |
Func<TInput, TValue> valueSelector) | |
{ | |
return input | |
.ToLookup(outerKeySelector) | |
.ToDictionaryWithDuplicateKeyCheck( | |
x => x.Key, | |
x => x.ToDictionaryWithDuplicateKeyCheck( | |
innerKeySelector, | |
valueSelector)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment