public void GetTypedSequence() { var sequenceData = _dataWithCovariantSequence.GetTypedSequence <string> (); Assert.That(sequenceData, Is.SameAs(_stringSequence)); var covariantSequenceData = _dataWithCovariantSequence.GetTypedSequence <object> (); Assert.That(covariantSequenceData, Is.SameAs(_stringSequence)); }
public override StreamedValue ExecuteInMemory <T> (StreamedSequence input) { ArgumentUtility.CheckNotNull("input", input); #if PORTABLE var method = typeof(Enumerable).GetMethod("Average", new[] { typeof(IEnumerable <T>) }); if (method == null || !(method.IsPublic && method.IsStatic)) { var message = string.Format("Cannot calculate the average of objects of type '{0}' in memory.", typeof(T).FullName); throw new NotSupportedException(message); } #else var method = typeof(Enumerable).GetMethod("Average", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(IEnumerable <T>) }, null); if (method == null) { var message = string.Format("Cannot calculate the average of objects of type '{0}' in memory.", typeof(T).FullName); throw new NotSupportedException(message); } #endif Debug.Assert(GetOutputDataInfo(input.DataInfo).DataType == method.ReturnType, "ReturnType of method matches return type of this operator"); var result = method.Invoke(null, new[] { input.GetTypedSequence <T>() }); return(new StreamedValue(result, (StreamedValueInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedValue ExecuteInMemory <T>(StreamedSequence input) { var sequence = input.GetTypedSequence <T>(); var result = ReturnDefaultWhenEmpty ? sequence.ElementAtOrDefault(_index) : sequence.ElementAt(_index); return(new StreamedValue(result, (StreamedValueInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedValue ExecuteInMemory <T> (StreamedSequence input) { var sequence = input.GetTypedSequence <T> (); var result = sequence.Max(); return(new StreamedValue(result, (StreamedValueInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedSequence ExecuteInMemory <T> (StreamedSequence input) { var sequence = input.GetTypedSequence <T> (); var result = sequence.Union((IEnumerable <T>)GetConstantSource2()); return(new StreamedSequence(result.AsQueryable(), (StreamedSequenceInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedValue ExecuteInMemory <T> (StreamedSequence input) { var sequence = input.GetTypedSequence <T> (); T result = ReturnDefaultWhenEmpty ? sequence.SingleOrDefault() : sequence.Single(); return(new StreamedValue(result, (StreamedValueInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedValue ExecuteInMemory <T>(StreamedSequence input) { var sequence = input.GetTypedSequence <T>(); var result = sequence.ToList(); return(new StreamedValue(result, new StreamedScalarValueInfo(typeof(ICollection <>).MakeGenericType(input.DataInfo.ResultItemType)))); }
public override StreamedSequence ExecuteInMemory <T> (StreamedSequence input) { var sequence = input.GetTypedSequence <T> (); var result = sequence.Take(GetConstantCount()); return(new StreamedSequence(result.AsQueryable(), GetOutputDataInfo(input.DataInfo))); }
/// <inheritdoc /> public override AsyncStreamedValue ExecuteInMemory <T>(StreamedSequence input) { var sequence = input.GetTypedSequence <T>(); var result = sequence.LongCount(); return(new AsyncStreamedValue(Task.FromResult(result), GetOutputDataInfo(input.DataInfo))); }
public override AsyncStreamedValue ExecuteInMemory <T>(StreamedSequence input) { var sequence = input.GetTypedSequence <T>(); T result = ReturnDefaultWhenEmpty ? sequence.FirstOrDefault() : sequence.First(); return(new AsyncStreamedValue(Task.FromResult(result), GetOutputDataInfo(input.DataInfo))); }
public override StreamedSequence ExecuteInMemory <T> (StreamedSequence input) { var sequence = input.GetTypedSequence <T> (); var result = sequence.Distinct(); return(new StreamedSequence(result.AsQueryable(), (StreamedSequenceInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedSequence ExecuteInMemory<T> (StreamedSequence input) { ArgumentUtility.CheckNotNull ("input", input); var sequence = input.GetTypedSequence<T> (); var result = sequence.Except (GetConstantSource2<T>()); return new StreamedSequence (result.AsQueryable (), (StreamedSequenceInfo) GetOutputDataInfo (input.DataInfo)); }
public override StreamedValue ExecuteInMemory <T>(StreamedSequence input) { var sequence = input.GetTypedSequence <T>(); var item = GetConstantItem <T>(); var result = sequence.Contains(item); return(new StreamedValue(result, (StreamedValueInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedSequence ExecuteInMemory <T> (StreamedSequence input) { var sequence = input.GetTypedSequence <T> (); IEnumerable <T> result = OptionalDefaultValue != null?sequence.DefaultIfEmpty((T)GetConstantOptionalDefaultValue()) : sequence.DefaultIfEmpty(); return(new StreamedSequence(result.AsQueryable(), (StreamedSequenceInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedSequence ExecuteInMemory <TInput>(StreamedSequence input) { var sequence = input.GetTypedSequence <TInput>(); var castMethod = s_enumerableCastMethod.MakeGenericMethod(CastItemType); var result = (IEnumerable)InvokeExecuteMethod(castMethod, sequence); return(new StreamedSequence(result.AsQueryable(), (StreamedSequenceInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedSequence ExecuteInMemory <TInput> (StreamedSequence input) { var sequence = input.GetTypedSequence <TInput> (); var castMethod = typeof(Enumerable).GetMethod("OfType", new[] { typeof(IEnumerable) }).MakeGenericMethod(SearchedItemType); var result = (IEnumerable)InvokeExecuteMethod(castMethod, sequence); return(new StreamedSequence(result.AsQueryable(), (StreamedSequenceInfo)GetOutputDataInfo(input.DataInfo))); }
/// <inheritdoc cref="ResultOperatorBase.ExecuteInMemory" /> public override StreamedValue ExecuteInMemory <T> (StreamedSequence input) { ArgumentUtility.CheckNotNull("input", input); var sequence = input.GetTypedSequence <T> (); var result = sequence.Any(); return(new StreamedValue(result, (StreamedValueInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedValue ExecuteInMemory <T>(StreamedSequence input) { var sequence = input.GetTypedSequence <T>(); var predicateLambda = ReverseResolvingExpressionTreeVisitor.ReverseResolve(input.DataInfo.ItemExpression, Predicate); var predicate = (Func <T, bool>)predicateLambda.Compile(); var result = sequence.All(predicate); return(new StreamedValue(result, (StreamedValueInfo)base.GetOutputDataInfo(input.DataInfo))); }
/// <inheritdoc cref="ResultOperatorBase.ExecuteInMemory" /> public override StreamedValue ExecuteInMemory <T>(StreamedSequence input) { var sequence = input.GetTypedSequence <T>(); var funcLambda = ReverseResolvingExpressionTreeVisitor.ReverseResolveLambda(input.DataInfo.ItemExpression, Func, 1); var func = (Func <T, T, T>)funcLambda.Compile(); var result = sequence.Aggregate(func); return(new StreamedValue(result, (StreamedValueInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedValue ExecuteInMemory <T> (StreamedSequence input) { ArgumentUtility.CheckNotNull("input", input); var sequence = input.GetTypedSequence <T> (); var item = GetConstantItem <T> (); var result = sequence.Contains(item); return(new StreamedValue(result, GetOutputDataInfo(input.DataInfo))); }
public override StreamedSequence ExecuteInMemory <TInput> (StreamedSequence input) { ArgumentUtility.CheckNotNull("input", input); var sequence = input.GetTypedSequence <TInput> (); var castMethod = typeof(Enumerable).GetMethod("Cast", new[] { typeof(IEnumerable) }).MakeGenericMethod(CastItemType); var result = (IEnumerable)InvokeExecuteMethod(castMethod, sequence); return(new StreamedSequence(result.AsQueryable(), (StreamedSequenceInfo)GetOutputDataInfo(input.DataInfo))); }
/// <inheritdoc /> public override AsyncStreamedValue ExecuteInMemory <T>(StreamedSequence input) { if (input == null) { throw new ArgumentNullException(nameof(input)); } var sequence = input.GetTypedSequence <T>(); var result = sequence.Min(); return(new AsyncStreamedValue(Task.FromResult(result), GetOutputDataInfo(input.DataInfo))); }
/// <inheritdoc cref="ResultOperatorBase.ExecuteInMemory" /> public override StreamedValue ExecuteInMemory <T> (StreamedSequence input) { ArgumentUtility.CheckNotNull("input", input); var sequence = input.GetTypedSequence <T> (); var predicateLambda = ReverseResolvingExpressionVisitor.ReverseResolve(input.DataInfo.ItemExpression, Predicate); var predicate = (Func <T, bool>)predicateLambda.Compile(); var result = sequence.All(predicate); return(new StreamedValue(result, GetOutputDataInfo(input.DataInfo))); }
public StreamedSequence ExecuteGroupingInMemory <TSource, TKey, TElement>(StreamedSequence input) { var inputSequence = input.GetTypedSequence <TSource>(); var keySelectorLambda = ReverseResolvingExpressionTreeVisitor.ReverseResolve(input.DataInfo.ItemExpression, KeySelector); var keySelector = (Func <TSource, TKey>)keySelectorLambda.Compile(); var elementSelectorLambda = ReverseResolvingExpressionTreeVisitor.ReverseResolve(input.DataInfo.ItemExpression, ElementSelector); var elementSelector = (Func <TSource, TElement>)elementSelectorLambda.Compile(); var resultSequence = inputSequence.GroupBy(keySelector, elementSelector); return(new StreamedSequence(resultSequence.AsQueryable(), (StreamedSequenceInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedValue ExecuteInMemory <T>(StreamedSequence input) { var method = typeof(Enumerable).GetMethod("Sum", new[] { typeof(IEnumerable <T>) }); if (method == null) { var message = string.Format("Cannot calculate the sum of objects of type '{0}' in memory.", typeof(T).FullName); throw new NotSupportedException(message); } var result = method.Invoke(null, new[] { input.GetTypedSequence <T>() }); return(new StreamedValue(result, (StreamedValueInfo)GetOutputDataInfo(input.DataInfo))); }
public override StreamedValue ExecuteInMemory <T> (StreamedSequence input) { ArgumentUtility.CheckNotNull("input", input); var method = typeof(Enumerable).GetRuntimeMethod("Average", new[] { typeof(IEnumerable <T>) }); if (method == null) { var message = string.Format("Cannot calculate the average of objects of type '{0}' in memory.", typeof(T).FullName); throw new NotSupportedException(message); } Assertion.DebugAssert(GetOutputDataInfo(input.DataInfo).DataType == method.ReturnType, "ReturnType of method matches return type of this operator"); var result = method.Invoke(null, new[] { input.GetTypedSequence <T>() }); return(new StreamedValue(result, GetOutputDataInfo(input.DataInfo))); }
/// <inheritdoc /> public override AsyncStreamedValue ExecuteInMemory <T>(StreamedSequence input) { if (input == null) { throw new ArgumentNullException(nameof(input)); } var typedSumMethod = typeof(Enumerable).GetMethod("Sum", new[] { typeof(IEnumerable <T>) }); if (typedSumMethod == null) { throw new NotSupportedException($"No in-memory sum method found for type {typeof(T).FullName}."); } var sequence = input.GetTypedSequence <T>(); var result = typedSumMethod.Invoke(null, new object[] { sequence }); return(new AsyncStreamedValue(Task.FromResult(result), GetOutputDataInfo(input.DataInfo))); }
/// <summary> /// Executes the aggregating operation in memory. /// </summary> /// <typeparam name="TInput">The type of the source items.</typeparam> /// <typeparam name="TAggregate">The type of the aggregated items.</typeparam> /// <typeparam name="TResult">The type of the result items.</typeparam> /// <param name="input">The input sequence.</param> /// <returns>A <see cref="StreamedValue"/> object holding the aggregated value.</returns> public StreamedValue ExecuteAggregateInMemory <TInput, TAggregate, TResult>(StreamedSequence input) { var sequence = input.GetTypedSequence <TInput>(); var seed = GetConstantSeed <TAggregate>(); var funcLambda = ReverseResolvingExpressionTreeVisitor.ReverseResolveLambda(input.DataInfo.ItemExpression, Func, 1); var func = (Func <TAggregate, TInput, TAggregate>)funcLambda.Compile(); var aggregated = sequence.Aggregate(seed, func); var outputDataInfo = (StreamedValueInfo)GetOutputDataInfo(input.DataInfo); if (OptionalResultSelector == null) { return(new StreamedValue(aggregated, outputDataInfo)); } else { var resultSelector = (Func <TAggregate, TResult>)OptionalResultSelector.Compile(); var result = resultSelector(aggregated); return(new StreamedValue(result, outputDataInfo)); } }
public override StreamedValue ExecuteInMemory <T> (StreamedSequence sequence) { return(new StreamedValue(sequence.GetTypedSequence <T> ().Count(), (StreamedValueInfo)GetOutputDataInfo(sequence.DataInfo))); }
public override StreamedSequence ExecuteInMemory <T>(StreamedSequence input) { var sequence = input.GetTypedSequence <T>(); return(new StreamedSequence(sequence.AsQueryable(), GetOutputDataInfo(input.DataInfo))); }