public void ReplaceMultipleParametersTest1() { Expression <Func <float, int, float> > expr = (x, y) => x * 2 + y * 3; Expression <Func <float, int, float> > exprReplacedValid = (x, y) => A.F1 * 2 + A.F2 * 3; var exprReplaced = LambdaParametersReplacer.ReplaceLambdaParameters(expr, new[] { Expression.Property(null, typeof(A), nameof(A.F1)), Expression.Property(null, typeof(A), nameof(A.F2)) }); Assert.IsTrue(CompareExpressionsExtensions.AreEqual(exprReplaced, exprReplacedValid.Body)); }
public void ReplaceOneParameterTest3() { Expression <Func <float, float> > expr = x => (int)Math.Truncate(x * 2 + x * 3); Expression <Func <float, float> > exprReplacedValid = x => (int)Math.Truncate(A.F1 * 2 + A.F1 * 3); var exprReplaced = LambdaParametersReplacer.ReplaceLambdaParameters(expr, new[] { Expression.Property(null, typeof(A), nameof(A.F1)) }); Assert.IsTrue(CompareExpressionsExtensions.AreEqual(exprReplaced, exprReplacedValid.Body)); }
public static SimpleOperationTarget ExtendWithSelector <TSource, TResult>(this SimpleOperationTarget sourceTarget, Expression <Func <TSource, TResult> > selector) { var normalSelector = new SelectorTransformer().TransformToNormalForm(selector); var t = LambdaParametersReplacer.ReplaceLambdaParameters((LambdaExpression)normalSelector, sourceTarget.Expression); return(new SimpleOperationTarget(t, sourceTarget.RootFastCollection)); }
public static SimpleOperationTarget BuildForSelector <TSource, TResult>( [NotNull] IFastCollection <TSource> rootFastCollection, [NotNull] Expression <Func <TSource, TResult> > selector) { var normalSelector = new SelectorTransformer().TransformToNormalForm(selector); var t = LambdaParametersReplacer.ReplaceLambdaParameters((LambdaExpression)normalSelector, new FastCollectionReferenceExpression(rootFastCollection)); return(new SimpleOperationTarget(t, rootFastCollection)); }
/// <summary> /// Transforms "where" predicate to inner presentation (which is used for execution). /// </summary> /// <param name="expression"></param> /// <param name="sourceOperationTarget">Lambda parameter of expression will be replaced with <see cref="OperationTargetExpression"/> containing this target</param> /// <typeparam name="TSource"></typeparam> /// <returns></returns> internal IFilter ParsePredicate <TSource>([NotNull] Expression <Func <TSource, bool> > expression, SimpleOperationTarget sourceOperationTarget) { var t = LambdaParametersReplacer.ReplaceLambdaParameters(expression, sourceOperationTarget.Expression); return(_filtersParser.ParseFilters(t)); }