A snippet to print nested IGrouping items from a GroupBy Linq.
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 LinqVisualizer | |
{ | |
public static void Dump<Tkey, Telement>(this IEnumerable<IGrouping<Tkey, Telement>> source) | |
{ | |
foreach (var item in source) | |
{ | |
Console.WriteLine("Root Level Key : {0}", item.Key); | |
foreach (var group in item) | |
{ | |
Dump(group, true); | |
} | |
} | |
} | |
public static void Dump(dynamic obj, bool isFirstLevel) | |
{ | |
if (obj.GetType().Name == "Grouping") | |
{ | |
Dump(obj); | |
} | |
else | |
{ | |
Console.WriteLine(" item - {0}", obj); | |
} | |
} | |
public static void Dump(dynamic source) | |
{ | |
Console.WriteLine(" Key - {0}", source.GetType().GetProperty("Key").GetValue(source)); | |
foreach (var item in source) | |
{ | |
Dump(item, false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment