/// <summary> /// Groups the elements of a sequence according to a specified key selector function and compares the keys by using a specified comparer. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> whose elements to group.</param> /// <param name="keySelector">A function to extract the key for each element.</param> /// <param name="comparer">An <see cref="T:System.Collections.Generic.IEqualityComparer`1"/> to compare keys.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An IEnumerable<IGrouping<TKey, TSource>> in C# or IEnumerable(Of IGrouping(Of TKey, TSource)) in Visual Basic where each <see cref="T:System.Linq.IGrouping`2"/> object contains a collection of objects and a key. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="keySelector"/> is null.</exception> public static IBindableCollection <IBindableGrouping <TKey, TSource> > GroupBy <TSource, TKey>(this IBindableCollection <TSource> source, Expression <Func <TSource, TKey> > keySelector, IEqualityComparer <TKey> comparer, DependencyDiscovery dependencyAnalysisMode) where TSource : class { return(source.GroupBy(keySelector, s => s, comparer, dependencyAnalysisMode)); }
/// <summary> /// Groups the elements of a sequence according to a key selector function. The keys are compared by using a comparer and each group's elements are projected by using a specified function. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> /// <typeparam name="TElement">The type of the elements in the <see cref="T:System.Linq.IGrouping`2"/>.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> whose elements to group.</param> /// <param name="keySelector">A function to extract the key for each element.</param> /// <param name="elementSelector">A function to map each source element to an element in an <see cref="T:System.Linq.IGrouping`2"/>.</param> /// <param name="comparer">An <see cref="T:System.Collections.Generic.IEqualityComparer`1"/> to compare keys.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An IEnumerable<IGrouping<TKey, TElement>> in C# or IEnumerable(Of IGrouping(Of TKey, TElement)) in Visual Basic where each <see cref="T:System.Linq.IGrouping`2"/> object contains a collection of objects of type TElement and a key. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> is null.</exception> public static IBindableCollection <IBindableGrouping <TKey, TElement> > GroupBy <TSource, TKey, TElement>(this IBindableCollection <TSource> source, Expression <Func <TSource, TKey> > keySelector, Expression <Func <TSource, TElement> > elementSelector, IEqualityComparer <TKey> comparer, DependencyDiscovery dependencyAnalysisMode) where TSource : class where TElement : class { source.ShouldNotBeNull("source"); keySelector.ShouldNotBeNull("keySelector"); elementSelector.ShouldNotBeNull("elementSelector"); var result = new GroupByIterator <TKey, TSource, TElement>(source, keySelector, elementSelector, comparer, source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { return(result.DependsOnExpression(keySelector.Body, keySelector.Parameters[0])); } return(result); }
/// <summary> /// Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. Key values are compared by using a specified comparer, and the elements of each group are projected by using a specified function. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> /// <typeparam name="TElement">The type of the elements in each <see cref="T:System.Linq.IGrouping`2"/>.</typeparam> /// <typeparam name="TResult">The type of the result value returned by <paramref name="resultSelector"/>.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> whose elements to group.</param> /// <param name="keySelector">A function to extract the key for each element.</param> /// <param name="elementSelector">A function to map each source element to an element in an <see cref="T:System.Linq.IGrouping`2"/>.</param> /// <param name="resultSelector">A function to create a result value from each group.</param> /// <param name="comparer">An <see cref="T:System.Collections.Generic.IEqualityComparer`1"/> to compare keys with.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// A collection of elements of type TResult where each element represents a projection over a group and its key. /// </returns> public static IBindableCollection <TResult> GroupBy <TSource, TKey, TElement, TResult>(this IBindableCollection <TSource> source, Expression <Func <TSource, TKey> > keySelector, Expression <Func <TSource, TElement> > elementSelector, Expression <Func <TKey, IBindableCollection <TElement>, TResult> > resultSelector, IEqualityComparer <TKey> comparer, DependencyDiscovery dependencyAnalysisMode) where TSource : class where TElement : class where TResult : class { return(source.GroupBy(keySelector, elementSelector, comparer, dependencyAnalysisMode).Into(resultSelector)); }
/// <summary> /// Groups the elements of a sequence according to a specified key selector function and projects the elements for each group by using a specified function. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> /// <typeparam name="TElement">The type of the elements in the <see cref="T:System.Linq.IGrouping`2"/>.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> whose elements to group.</param> /// <param name="keySelector">A function to extract the key for each element.</param> /// <param name="elementSelector">A function to map each source element to an element in the <see cref="T:System.Linq.IGrouping`2"/>.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An IEnumerable<IGrouping<TKey, TElement>> in C# or IEnumerable(Of IGrouping(Of TKey, TElement)) in Visual Basic where each <see cref="T:System.Linq.IGrouping`2"/> object contains a collection of objects of type TElement and a key. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> is null.</exception> public static IBindableCollection <IBindableGrouping <TKey, TElement> > GroupBy <TSource, TKey, TElement>(this IBindableCollection <TSource> source, Expression <Func <TSource, TKey> > keySelector, Expression <Func <TSource, TElement> > elementSelector, DependencyDiscovery dependencyAnalysisMode) where TSource : class where TElement : class { return(source.GroupBy(keySelector, elementSelector, null, dependencyAnalysisMode)); }
/// <summary> /// Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> /// <typeparam name="TResult">The type of the result value returned by <paramref name="resultSelector"/>.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> whose elements to group.</param> /// <param name="keySelector">A function to extract the key for each element.</param> /// <param name="resultSelector">A function to create a result value from each group.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// A collection of elements of type TResult where each element represents a projection over a group and its key. /// </returns> public static IBindableCollection <TResult> GroupBy <TSource, TKey, TResult>(this IBindableCollection <TSource> source, Expression <Func <TSource, TKey> > keySelector, Expression <Func <TKey, IBindableCollection <TSource>, TResult> > resultSelector, DependencyDiscovery dependencyAnalysisMode) where TSource : class where TResult : class { return(source.GroupBy(keySelector, s => s, new DefaultComparer <TKey>(), dependencyAnalysisMode).Into(resultSelector)); }
/// <summary> /// Performs a subsequent ordering of the elements in a sequence in ascending order by using a specified comparer. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> /// <param name="source">An <see cref="T:System.Linq.IOrderedEnumerable`1"/> that contains elements to sort.</param> /// <param name="keySelector">A function to extract a key from each element.</param> /// <param name="comparer">An <see cref="T:System.Collections.Generic.IComparer`1"/> to compare keys.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="T:System.Linq.IOrderedEnumerable`1"/> whose elements are sorted according to a key. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="keySelector"/> is null.</exception> public static IOrderedBindableCollection <TSource> ThenBy <TSource, TKey>(this IOrderedBindableCollection <TSource> source, Expression <Func <TSource, TKey> > keySelector, IComparer <TKey> comparer, DependencyDiscovery dependencyAnalysisMode) where TSource : class { source.ShouldNotBeNull("source"); keySelector.ShouldNotBeNull("keySelector"); var result = source.CreateOrderedIterator(keySelector.Compile(), comparer, false); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { return(result.DependsOnExpression(keySelector.Body, keySelector.Parameters[0])); } return(result); }
/// <summary> /// Projects a single bindable object into another bindable object, using a lambda to select the new /// type of object. /// </summary> /// <typeparam name="TSource">The type of the source.</typeparam> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="source">The source colection.</param> /// <param name="projector">The projector function used to turn the source type into the result type.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An object created by the <paramref name="projector"/>. If the source value changes, the item will be projected again. /// </returns> public static IBindable <TResult> Project <TSource, TResult>(this IBindable <TSource> source, Expression <Func <TSource, TResult> > projector, DependencyDiscovery dependencyAnalysisMode) { source.ShouldNotBeNull("source"); projector.ShouldNotBeNull("projector"); var result = new ProjectOperator <TSource, TResult>(source, projector.Compile(), source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { return(result.DependsOnExpression(projector.Body, projector.Parameters[0])); } return(result); }
/// <summary> /// Sorts the elements of a sequence in ascending order by using a specified comparer. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> /// <param name="source">A sequence of values to order.</param> /// <param name="keySelector">A function to extract a key from an element.</param> /// <param name="comparer">An <see cref="T:System.Collections.Generic.IComparer`1"/> to compare keys.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="T:System.Linq.IOrderedEnumerable`1"/> whose elements are sorted according to a key. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="keySelector"/> is null.</exception> public static IOrderedBindableCollection <TSource> OrderBy <TSource, TKey>(this IBindableCollection <TSource> source, Expression <Func <TSource, TKey> > keySelector, IComparer <TKey> comparer, DependencyDiscovery dependencyAnalysisMode) where TSource : class { source.ShouldNotBeNull("source"); keySelector.ShouldNotBeNull("keySelector"); var result = new OrderByIterator <TSource, TKey>(source, new ItemSorter <TSource, TKey>(null, keySelector.Compile(), comparer, true), source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { return(result.DependsOnExpression(keySelector.Body, keySelector.Parameters[0])); } return(result); }
/// <summary> /// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> /// <param name="source">An <see cref="T:System.Linq.IOrderedEnumerable`1"/> that contains elements to sort.</param> /// <param name="keySelector">A function to extract a key from each element.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="T:System.Linq.IOrderedEnumerable`1"/> whose elements are sorted according to a key. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="keySelector"/> is null.</exception> public static IOrderedBindableCollection <TSource> ThenBy <TSource, TKey>(this IOrderedBindableCollection <TSource> source, Expression <Func <TSource, TKey> > keySelector, DependencyDiscovery dependencyAnalysisMode) where TSource : class { return(source.ThenBy(keySelector, null, dependencyAnalysisMode)); }
/// <summary> /// Projects each element of a sequence into a new form. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <param name="source">A sequence of values to invoke a transform function on.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="IBindableCollection{TElement}"/> whose elements are the result of invoking the transform function on each element of <paramref name="source"/>. /// </returns> /// <exception cref="T:System.ArgumentNullException"><paramref name="source"/> is null.</exception> public static IBindableCollection <TSource> Select <TSource>(this IBindableCollection <TSource> source, DependencyDiscovery dependencyAnalysisMode) where TSource : class { return(source.Select(s => s, dependencyAnalysisMode)); }
/// <summary> /// Projects each element of a sequence into a new form. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TResult">The type of the value returned by <paramref name="selector"/>.</typeparam> /// <param name="source">A sequence of values to invoke a transform function on.</param> /// <param name="selector">A transform function to apply to each element.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="IBindableCollection{TElement}"/> whose elements are the result of invoking the transform function on each element of <paramref name="source"/>. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="selector"/> is null.</exception> public static IBindableCollection <TResult> Select <TSource, TResult>(this IBindableCollection <TSource> source, Expression <Func <TSource, TResult> > selector, DependencyDiscovery dependencyAnalysisMode) where TSource : class { source.ShouldNotBeNull("source"); selector.ShouldNotBeNull("selector"); var result = new SelectIterator <TSource, TResult>(source, selector.Compile(), source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { result = result.DependsOnExpression(selector.Body, selector.Parameters[0]); } return(result); }
/// <summary> /// Projects each element of a sequence to an <see cref="IBindableCollection{TElement}"/> and flattens the resulting sequences into one sequence. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TResult">The type of the elements of the sequence returned by <paramref name="selector"/>.</typeparam> /// <param name="source">A sequence of values to project.</param> /// <param name="selector">A transform function to apply to each element.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="IBindableCollection{TElement}"/> whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="selector"/> is null.</exception> public static IBindableCollection <TResult> SelectMany <TSource, TResult>(this IBindableCollection <TSource> source, Expression <Func <TSource, IBindableCollection <TResult> > > selector, DependencyDiscovery dependencyAnalysisMode) where TSource : class where TResult : class { source.ShouldNotBeNull("source"); return(source.Select(selector, dependencyAnalysisMode).UnionAll()); }
/// <summary> /// Applies an accumulator function over a sequence. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TSource}"/> to aggregate over.</param> /// <param name="func">An accumulator function to be invoked on each element.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns>The final accumulator value.</returns> public static IBindable <TResult> Aggregate <TSource, TResult>(this IBindableCollection <TSource> source, Expression <Func <IBindableCollection <TSource>, TResult> > func, DependencyDiscovery dependencyAnalysisMode) { source.ShouldNotBeNull("source"); func.ShouldNotBeNull("func"); var result = new CustomAggregator <TSource, TResult>(source, func.Compile(), source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { return(result.DependsOnExpression(func, func.Parameters[0])); } return(result); }
/// <summary> /// Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TAccumulate">The type of the accumulator value.</typeparam> /// <typeparam name="TResult">The type of the resulting value.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> to aggregate over.</param> /// <param name="seed">The initial accumulator value.</param> /// <param name="func">An accumulator function to be invoked on each element.</param> /// <param name="resultSelector">A function to transform the final accumulator value into the result value.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns>The transformed final accumulator value.</returns> public static IBindable <TResult> Aggregate <TSource, TAccumulate, TResult>(this IBindableCollection <TSource> source, TAccumulate seed, Expression <Func <TAccumulate, TSource, TAccumulate> > func, Expression <Func <TAccumulate, TResult> > resultSelector, DependencyDiscovery dependencyAnalysisMode) { return(source.Aggregate(seed, func, dependencyAnalysisMode).Project(resultSelector, dependencyAnalysisMode)); }
/// <summary> /// Applies an accumulator function over a sequence. The specified seed value is used as the /// initial accumulator value. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TAccumulate">The type of the accumulator value.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> to aggregate over.</param> /// <param name="seed">The initial accumulator value.</param> /// <param name="func">An accumulator function to be invoked on each element.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns>The final accumulator value.</returns> public static IBindable <TAccumulate> Aggregate <TSource, TAccumulate>(this IBindableCollection <TSource> source, TAccumulate seed, Expression <Func <TAccumulate, TSource, TAccumulate> > func, DependencyDiscovery dependencyAnalysisMode) { source.ShouldNotBeNull("source"); func.ShouldNotBeNull("func"); seed.ShouldNotBeNull("seed"); var compiledAccumulator = func.Compile(); var function = new Func <IBindableCollection <TSource>, TAccumulate>( sourceElements => { var current = seed; foreach (var sourceElement in sourceElements) { current = compiledAccumulator(current, sourceElement); } return(current); } ); var result = new CustomAggregator <TSource, TAccumulate>(source, function, source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { return(result.DependsOnExpression(func, func.Parameters[1])); } return(result); }
/// <summary> /// Bindable LINQ: Filters a sequence of values based on a predicate. Each item will be re-evaluated if it raises a property changed event, or if any properties /// accessed in the filter expression raise events. Items will be re-evaluated when the source collection raises CollectionChanged events. The entire collection /// will be re-evaluated if the source collection raises a Reset event, or if any addtional dependencies added via the <see cref="WithDependencies{TResult}"/> /// extension method tell it to re-evaluate. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <param name="source">An <see cref="IBindableCollection{TElement}"/> to filter.</param> /// <param name="predicate">A function to test each element for a condition.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="IBindableCollection{TElement}"/> that contains elements from the input sequence that satisfy the condition. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="predicate"/> is null.</exception> public static IBindableCollection <TSource> Where <TSource>(this IBindableCollection <TSource> source, Expression <Func <TSource, bool> > predicate, DependencyDiscovery dependencyAnalysisMode) where TSource : class { source.ShouldNotBeNull("source"); predicate.ShouldNotBeNull("predicate"); var result = new WhereIterator <TSource>(source, predicate.Compile(), source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { return(result.DependsOnExpression(predicate.Body, predicate.Parameters[0])); } return(result); }