Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. public static class Extensions
  2. {
  3. public static Dictionary<TKeyOuter, Dictionary<TKeyMiddle, Dictionary<TKeyInner, TValue>>> ToThreeLevelDictionary<TKeyOuter, TKeyMiddle, TKeyInner, TValue, TInput>(
  4. this IEnumerable<TInput> input,
  5. Func<TInput, TKeyOuter> outerKeySelector,
  6. Func<TInput, TKeyMiddle> middleKeySelector,
  7. Func<TInput, TKeyInner> innerKeySelector,
  8. Func<TInput, TValue> valueSelector)
  9. {
  10. return input
  11. .ToLookup(outerKeySelector)
  12. .ToDictionaryWithDuplicateKeyCheck(
  13. x => x.Key,
  14. x => x.ToTwoLevelDictionary(middleKeySelector, innerKeySelector, valueSelector));
  15. }
  16.  
  17. public static Dictionary<TKeyOuter, Dictionary<TKeyInner, TValue>> ToTwoLevelDictionary<TKeyOuter, TKeyInner, TValue, TInput>(
  18. this IEnumerable<TInput> input,
  19. Func<TInput, TKeyOuter> outerKeySelector,
  20. Func<TInput, TKeyInner> innerKeySelector,
  21. Func<TInput, TValue> valueSelector)
  22. {
  23. return input
  24. .ToLookup(outerKeySelector)
  25. .ToDictionaryWithDuplicateKeyCheck(
  26. x => x.Key,
  27. x => x.ToDictionaryWithDuplicateKeyCheck(
  28. innerKeySelector,
  29. valueSelector));
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement