/// <summary> /// Returns first 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>first sibling of given item or default value if there are no siblings. </returns> public static TResult FirstSiblingOrDefault <TResult, TFilter>(this IQueryable <TResult> collection, TFilter item) where TResult : IHasTreeEntry where TFilter : IHasTreeEntry { return(collection.Where(i => i.TreeEntry, NestedIntervalsSpec.SiblingsBefore(item.TreeEntry, true)) .OrderBy(i => i.TreeEntry.Nv).FirstOrDefault()); }
/// <summary> /// Filter a sequence of values to return sibling elements of given item, positioned before 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 before it. </returns> public static IQueryable <TResult> SiblingsBefore <TResult, TFilter>( this IQueryable <TResult> collection, TFilter item, bool includeSelf = false) where TResult : IHasTreeEntry where TFilter : IHasTreeEntry { return(collection.Where(i => i.TreeEntry, NestedIntervalsSpec.SiblingsBefore(item.TreeEntry, includeSelf))); }