Created
June 20, 2013 06:30
-
-
Save pregress/5820672 to your computer and use it in GitHub Desktop.
TraverseTree
This file contains hidden or 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 IEnumerable<T> TraverseTree<T>(this T parent, Func<T, IEnumerable<T>> getChildren) | |
{ | |
yield return parent; | |
foreach (var child in getChildren(parent)) | |
{ | |
foreach (var item in child.TraverseTree(getChildren)) | |
{ | |
yield return item; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment