Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save johnathan-sewell/2688592 to your computer and use it in GitHub Desktop.
Save johnathan-sewell/2688592 to your computer and use it in GitHub Desktop.
EPiServer tree recursive methods
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