Esempio n. 1
0
        internal static Expression <Func <TResult> > ApplyParameters <TParameter0, TParameter1, TResult>(this Expression <Func <TParameter0, TParameter1, TResult> > func, TParameter0 parameter0Value, TParameter1 parameter1Value)
        {
            Expression body = new ReplaceParameterVisitor(new Dictionary <ParameterExpression, Expression>()
            {
                { func.Parameters[0], Expression.Constant(parameter0Value, func.Parameters[0].Type) }, { func.Parameters[1], Expression.Constant(parameter1Value, func.Parameters[1].Type) }
            }).Visit(func.Body);

            // ReSharper disable once AssignNullToNotNullAttribute
            return(Expression.Lambda <Func <TResult> >(body));
        }
Esempio n. 2
0
        internal static LambdaExpression ApplyParameters(this LambdaExpression lambdaExpression, object[] parameterValues)
        {
            Dictionary <ParameterExpression, Expression> replacements = new Dictionary <ParameterExpression, Expression>();

            for (int index = 0; index < parameterValues.Length; index++)
            {
                replacements.Add(lambdaExpression.Parameters[index], Expression.Constant(parameterValues[index], lambdaExpression.Parameters[index].Type));
            }

            Expression body = new ReplaceParameterVisitor(replacements).Visit(lambdaExpression.Body);

            return(Expression.Lambda(body));
        }
        private static Expression <Func <ZipPair <int, TSourceItem>, bool> > getZipPairPredicateExpression(Expression <Func <TSourceItem, bool> > predicateExpression)
        {
            ParameterExpression zipPairParameterExpression
                = Expression.Parameter(typeof(ZipPair <int, TSourceItem>), "zipPair");
            Expression zipPairItem2Expression
                = Expression.PropertyOrField(
                      zipPairParameterExpression,
                      nameof(ZipPair <int, TSourceItem> .RightItem));
            ReplaceParameterVisitor replaceParameterVisitor
                = new ReplaceParameterVisitor(
                      predicateExpression.Parameters[0],
                      zipPairItem2Expression);
            Expression <Func <ZipPair <int, TSourceItem>, bool> > zipPairPredicateExpression
                = Expression.Lambda <Func <ZipPair <int, TSourceItem>, bool> >(
                      replaceParameterVisitor.Visit(predicateExpression.Body),
                      zipPairParameterExpression);

            return(zipPairPredicateExpression);
        }
Esempio n. 4
0
        private static Expression <Func <ZipPair <int, TSourceItem>, bool> > getZipPairNotPredicateExpression(Expression <Func <TSourceItem, int, bool> > predicateExpression)
        {
            ParameterExpression zipPairParameterExpression
                = Expression.Parameter(typeof(ZipPair <int, TSourceItem>), "zipPair");
            Expression zipPairIndexExpression
                = Expression.PropertyOrField(
                      zipPairParameterExpression,
                      nameof(ZipPair <int, TSourceItem> .LeftItem));
            Expression zipPairItemExpression
                = Expression.PropertyOrField(
                      zipPairParameterExpression,
                      nameof(ZipPair <int, TSourceItem> .RightItem));
            ReplaceParameterVisitor replaceParameterVisitor
                = new ReplaceParameterVisitor(
                      predicateExpression.Parameters,
                      new[] { zipPairItemExpression, zipPairIndexExpression });
            Expression <Func <ZipPair <int, TSourceItem>, bool> > zipPairNotPredicateExpression
                = Expression.Lambda <Func <ZipPair <int, TSourceItem>, bool> >(
                      // ReSharper disable once AssignNullToNotNullAttribute
                      Expression.Not(replaceParameterVisitor.Visit(predicateExpression.Body)),
                      zipPairParameterExpression);

            return(zipPairNotPredicateExpression);
        }
        private static Expression <Func <ZipPair <int, TSourceItem>, INotifyCollectionChanged> > getZipPairSelectorExpression(Expression <Func <TSourceItem, int, INotifyCollectionChanged> > selectorExpression)
        {
            ParameterExpression zipPairParameterExpression
                = Expression.Parameter(typeof(ZipPair <int, TSourceItem>), "zipPair");
            Expression zipPairIndexExpression
                = Expression.PropertyOrField(
                      zipPairParameterExpression,
                      nameof(ZipPair <int, TSourceItem> .LeftItem));
            Expression zipPairItemExpression
                = Expression.PropertyOrField(
                      zipPairParameterExpression,
                      nameof(ZipPair <int, TSourceItem> .RightItem));
            ReplaceParameterVisitor replaceParameterVisitor
                = new ReplaceParameterVisitor(
                      selectorExpression.Parameters,
                      new[] { zipPairItemExpression, zipPairIndexExpression });
            Expression <Func <ZipPair <int, TSourceItem>, INotifyCollectionChanged> > zipPairSelectorExpression
                = Expression.Lambda <Func <ZipPair <int, TSourceItem>, INotifyCollectionChanged> >(
                      // ReSharper disable once AssignNullToNotNullAttribute
                      replaceParameterVisitor.Visit(selectorExpression.Body),
                      zipPairParameterExpression);

            return(zipPairSelectorExpression);
        }
Esempio n. 6
0
        private static Expression <Func <JoinPair <TOuterSourceItem, TInnerSourceItem>, bool> > getJoinPairPredicateExpression(Expression <Func <TOuterSourceItem, TInnerSourceItem, bool> > joinPredicateExpression)
        {
            ParameterExpression joinPairParameterExpression
                = Expression.Parameter(typeof(JoinPair <TOuterSourceItem, TInnerSourceItem>), "joinPair");
            Expression joinPairOuterItemExpression
                = Expression.PropertyOrField(
                      joinPairParameterExpression,
                      nameof(JoinPair <TOuterSourceItem, TInnerSourceItem> .OuterItem));
            Expression joinPairInnerItemExpression
                = Expression.PropertyOrField(
                      joinPairParameterExpression,
                      nameof(JoinPair <TOuterSourceItem, TInnerSourceItem> .InnerItem));
            ReplaceParameterVisitor replaceParameterVisitor
                = new ReplaceParameterVisitor(
                      joinPredicateExpression.Parameters,
                      new[] { joinPairOuterItemExpression, joinPairInnerItemExpression });
            Expression <Func <JoinPair <TOuterSourceItem, TInnerSourceItem>, bool> > joinPairPredicateExpression
                = Expression.Lambda <Func <JoinPair <TOuterSourceItem, TInnerSourceItem>, bool> >(
                      // ReSharper disable once AssignNullToNotNullAttribute
                      replaceParameterVisitor.Visit(joinPredicateExpression.Body),
                      joinPairParameterExpression);

            return(joinPairPredicateExpression);
        }