/// <summary> /// Returns last sibling of given item, or default value if there are no siblings. /// </summary> /// <param name="collection">Sequence to filter. </param> /// <param name="item">Item to find siblings for. </param> /// <typeparam name="TResult">Type of sequence containing item siblings. Should implement <see cref="IHasTreeEntry"/>. </typeparam> /// <typeparam name="TFilter">Type of referenced item to use in query. Should implement <see cref="IHasTreeEntry"/>. </typeparam> /// <returns>last sibling of given item or default value if there are no siblings. </returns> public static TResult LastSiblingOrDefault <TResult, TFilter>(this IQueryable <TResult> collection, TFilter item) where TResult : IHasTreeEntry where TFilter : IHasTreeEntry { return(collection.Where(i => i.TreeEntry, NestedIntervalsSpec.SiblingsAfter(item.TreeEntry, true)) .OrderBy(i => i.TreeEntry.Nv).LastOrDefault()); }
/// <summary> /// Filter a sequence of values to return sibling elements of given item, positioned after it. /// Item considered as sibling if it's children of same parent item. /// </summary> /// <param name="collection">Sequence to filter. </param> /// <param name="item">Item to find siblings for. </param> /// <param name="includeSelf">Whether or not to include referenced item itself in list of siblings. false by default. </param> /// <typeparam name="TResult">Type of sequence containing item siblings. Should implement <see cref="IHasTreeEntry"/>. </typeparam> /// <typeparam name="TFilter">Type of referenced item to use in query. Should implement <see cref="IHasTreeEntry"/>. </typeparam> /// <returns>Sequence of sibling items of given item, positioned after it. </returns> public static IQueryable <TResult> SiblingsAfter <TResult, TFilter>( this IQueryable <TResult> collection, TFilter item, bool includeSelf = false) where TResult : IHasTreeEntry where TFilter : IHasTreeEntry { return(collection.Where(i => i.TreeEntry, NestedIntervalsSpec.SiblingsAfter(item.TreeEntry, includeSelf))); }