Created
May 13, 2012 13:59
-
-
Save johnathan-sewell/2688592 to your computer and use it in GitHub Desktop.
EPiServer tree recursive methods
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
protected static void FindDescendantsOfType<T>(PageData page, ICollection<T> descendants) where T : class | |
{ | |
var children = DataFactory.Instance.GetChildren(page.PageLink); | |
foreach (var child in children) | |
{ | |
if (child is T) | |
{ | |
descendants.Add(child as T); | |
} | |
FindDescendantsOfType(child, descendants); | |
} | |
} | |
protected static T FindParentOfType<T>(PageData currentPage) where T : class | |
{ | |
var parent = DataFactory.Instance.GetPage(currentPage.ParentLink); | |
if (parent == null) | |
{ | |
return null; | |
} | |
if (parent is T) | |
{ | |
return parent as T; | |
} | |
return FindParentOfType<T>(parent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment