Beispiel #1
0
 /// <summary>
 /// Filters a sequence of values to include only ancestors (parents and all parents of parents) of given item.
 /// </summary>
 /// <param name="collection">sequence to filter. </param>
 /// <param name="item">child item to find it's ancestors. </param>
 /// <param name="depth">Level of inheritance to filter ancestors.
 /// 1 returns only direct parents, 2 - parents of parents etc.
 /// -1 to return all ancestors up to root items.
 /// -1 by default. </param>
 /// <param name="includeSelf">Whether or not to include given child item itself in list. false by default. </param>
 /// <typeparam name="TResult">Type of sequence containing ancestors elements. Should implement <see cref="IHasTreeEntry"/>. </typeparam>
 /// <typeparam name="TFilter">Type of referenced item to use in filter. Should implement <see cref="IHasTreeEntry"/>. </typeparam>
 /// <returns>Sequence of ancestors of given item. </returns>
 public static IQueryable <TResult> AncestorsOf <TResult, TFilter>(
     this IQueryable <TResult> collection,
     TFilter item,
     int depth        = -1,
     bool includeSelf = false)
     where TResult : IHasTreeEntry
     where TFilter : IHasTreeEntry
 {
     return(collection.Where(i => i.TreeEntry, NestedIntervalsSpec.AncestorsOf(item, depth, includeSelf)));
 }
Beispiel #2
0
 /// <summary>
 /// Filters a sequence of values to include only ancestors (parents and all parents of parents) of given item.
 /// </summary>
 /// <param name="collection">sequence to filter. </param>
 /// <param name="navigateExpr">Property expression returning path to IHasTreeEntry item. </param>
 /// <param name="item">child item to find it's ancestors. </param>
 /// <param name="depth">Level of inheritance to filter ancestors.
 /// 1 returns only direct parents, 2 - parents of parents etc.
 /// -1 to return all ancestors up to root items.
 /// -1 by default. </param>
 /// <param name="includeSelf">Whether or not to include given child item itself in list. false by default. </param>
 /// <typeparam name="TResult">Type of sequence containing ancestors elements. </typeparam>
 /// <typeparam name="TFilter">Type of referenced item to use in filter. Should implement <see cref="IHasTreeEntry"/>. </typeparam>
 /// <returns>Sequence of ancestors of given item. </returns>
 public static IQueryable <TResult> AncestorsOf <TResult, TFilter>(
     this IQueryable <TResult> collection,
     Expression <Func <TResult, IHasTreeEntry> > navigateExpr,
     TFilter item,
     int depth        = -1,
     bool includeSelf = false)
     where TFilter : IHasTreeEntry
 {
     return(collection.Where(navigateExpr.Navigate(i => i.TreeEntry), NestedIntervalsSpec.AncestorsOf(item, depth, includeSelf)));
 }