/// <summary> /// Returns all descendants of <typeparamref name="T" /> type for provided page and level deep. /// </summary> /// <typeparam name="T">Type of pages to look for.</typeparam> /// <param name="pageData">The page for which to find descendants.</param> /// <param name="levels">Level of how deep to look for descendants in page hiararchy.</param> /// <returns>Returns sequence of PageData of descendants for provided page.</returns> public static IEnumerable <T> GetDescendants <T>(this PageData pageData, int levels) where T : PageData { if (pageData == null || levels <= 0) { yield break; } foreach (var child in pageData.GetChildren <T>()) { yield return(child); if (levels <= 1) { continue; } foreach (var grandChild in child.GetDescendants <T>(levels - 1)) { yield return(grandChild); } } }
/// <summary> /// Returns all child pages of PageData type for provided parent page. /// </summary> /// <param name="parentPage">Parent page of PageData type for which to return children.</param> /// <returns>Returns PageDataCollection of child pages.</returns> public static PageDataCollection GetChildren(this PageData parentPage) { return(parentPage.GetChildren <PageData>().ToPageDataCollection()); }
public static bool HasChildren(this PageData CurrentPage) { return(CurrentPage.GetChildren().Any()); }