/// <summary> /// Returns a sequence with all the EPiServer pages of given type <typeparamref name="T" /> in a LinkItemCollection /// </summary> /// <param name="linkItemCollection">Source LinkItemCollection to look for EPiServer pages.</param> /// <returns>Sequence of the EPiServer pages of type <typeparamref name="T" /> in a LinkItemCollection</returns> public static IEnumerable <T> ToEnumerable <T>(this LinkItemCollection linkItemCollection) where T : PageData { if (linkItemCollection == null) { return(Enumerable.Empty <T>()); } var contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>(); return(linkItemCollection .Select(x => x.ToContentReference()) .Where(x => !x.IsNullOrEmpty()) .Select(contentLoader.Get <IContent>) .SafeOfType <T>()); }
/// <summary> /// Find the corresponding links from a <see cref="LinkItemCollection"/> /// </summary> /// <param name="linkCollection">Collection of LinkItems</param> /// <returns>A collection of <see cref="GroLinkItem"/></returns> public static IEnumerable <GroLinkItem> GetGroLinkItems(this LinkItemCollection linkCollection) => linkCollection?.Select(GroLinkItem.FromLinkItem) ?? new GroLinkItem[] { };