当前位置: 首页>>代码示例>>C#>>正文


C# BinaryExpression.Update方法代码示例

本文整理汇总了C#中System.Linq.Expressions.BinaryExpression.Update方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryExpression.Update方法的具体用法?C# BinaryExpression.Update怎么用?C# BinaryExpression.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Linq.Expressions.BinaryExpression的用法示例。


在下文中一共展示了BinaryExpression.Update方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitBinary

            protected override Expression VisitBinary(BinaryExpression node)
            {
                // NB: This reduces assignment operators so that the stack spiller doesn't have to worry about it.
                if (node.CanReduce)
                {
                    return ReduceAndCheck(node);
                }

                // NB: Stack spilling of short-circuiting operators would undo the short-circuiting behavior due
                //     to evaluation of left and right for assignment into temps. We can avoid having to worry
                //     about this by reducing these nodes into more primitive conditionals and bitwise operators.
                //
                // CONSIDER: This could be moved to the stack spiller. See remarks on Reduce methods below.

                switch (node.NodeType)
                {
                    case ExpressionType.AndAlso:
                    case ExpressionType.OrElse:
                    case ExpressionType.Coalesce:
                        var hasAwait = false;

                        var left = default(Expression);
                        hasAwait |= VisitAndFindAwait(node.Left, out left);

                        var conversion = VisitAndConvert(node.Conversion, nameof(VisitBinary));

                        var right = default(Expression);
                        hasAwait |= VisitAndFindAwait(node.Right, out right);

                        var rewritten = node.Update(left, conversion, right);

                        if (hasAwait)
                        {
                            switch (node.NodeType)
                            {
                                case ExpressionType.AndAlso:
                                case ExpressionType.OrElse:
                                    return ReduceLogical(rewritten);
                                case ExpressionType.Coalesce:
                                    return ReduceCoalesce(rewritten);
                            }
                        }

                        return rewritten;
                }

                return base.VisitBinary(node);
            }
开发者ID:bartdesmet,项目名称:ExpressionFutures,代码行数:48,代码来源:Reducer.cs

示例2: VisitBinary

        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used 
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected override Expression VisitBinary(BinaryExpression node)
        {
            var newLeft = Visit(node.Left);
            var newRight = Visit(node.Right);

            if (((node.NodeType == ExpressionType.Equal)
                 || (node.NodeType == ExpressionType.NotEqual))
                && (node.Left.Type == typeof(bool))
                && (node.Right.Type == typeof(bool)))
            {
                var simpleLeft = node.Left.IsSimpleExpression();
                var simpleRight = node.Right.IsSimpleExpression();

                if (!simpleLeft
                    || !simpleRight)
                {
                    var leftOperand = simpleLeft
                        ? newLeft
                        : Expression.Condition(
                            newLeft,
                            Expression.Constant(true),
                            Expression.Constant(false),
                            typeof(bool));

                    var rightOperand = simpleRight
                        ? newRight
                        : Expression.Condition(
                            newRight,
                            Expression.Constant(true),
                            Expression.Constant(false),
                            typeof(bool));

                    return node.NodeType == ExpressionType.Equal
                        ? Expression.Equal(leftOperand, rightOperand)
                        : Expression.NotEqual(leftOperand, rightOperand);
                }
            }

            return node.Update(newLeft, node.Conversion, newRight);
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:44,代码来源:EqualityPredicateExpandingVisitor.cs

示例3: VisitBinary

		protected override Expression VisitBinary(BinaryExpression node)
		{
			if (node.NodeType != ExpressionType.AndAlso && node.NodeType != ExpressionType.OrElse)
			{
				return base.VisitBinary(node);
			}

			var left = node.Left.StripQuotes();
			var right = node.Right.StripQuotes();

			if (CanMakeEqualTrueFalse(left))
			{
				left = MakeEqualTrueFalse(left);
			}

			if (CanMakeEqualTrueFalse(right))
			{
				right = MakeEqualTrueFalse(right);
			}

			return base.VisitBinary(node.Update(left, VisitAndConvert(node.Conversion, "VisitBinary"), right));
		}
开发者ID:s-KaiNet,项目名称:Untech.SharePoint,代码行数:22,代码来源:BoolEqualityModifier.cs

示例4: VisitBinary

        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used 
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected override Expression VisitBinary(BinaryExpression node)
        {
            var newLeft = Visit(node.Left);
            var newRight = Visit(node.Right);

            if (!IsOptimalExpansion)
            {
                return node;
            }

            if ((node.NodeType == ExpressionType.Equal)
                || (node.NodeType == ExpressionType.NotEqual))
            {
                var leftIsNull = BuildIsNullExpression(newLeft);
                var rightIsNull = BuildIsNullExpression(newRight);

                var leftNullable = leftIsNull != null;
                var rightNullable = rightIsNull != null;

                if ((node.NodeType == ExpressionType.Equal)
                    && leftNullable
                    && rightNullable)
                {
                    return Expression.OrElse(
                        Expression.Equal(newLeft, newRight),
                        Expression.AndAlso(leftIsNull, rightIsNull));
                }

                if ((node.NodeType == ExpressionType.NotEqual)
                    && (leftNullable || rightNullable))
                {
                    IsOptimalExpansion = false;
                }
            }

            return node.Update(newLeft, node.Conversion, newRight);
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:41,代码来源:RelationalNullsOptimizedExpandingVisitor.cs

示例5: VisitBinary

        protected override Expression VisitBinary(BinaryExpression node)
        {
            var children = new[] {node.Left, node.Right};

            VisitChildren(children);

            return node.Update(children[0], node.Conversion, children[1]);
        }
开发者ID:RossMerr,项目名称:CouchbaseNetClient,代码行数:8,代码来源:LambdaSimplifyingExpressionVisitor.cs

示例6: replaceBinaryNodeChild

 private BinaryExpression replaceBinaryNodeChild(BinaryExpression node, Expression oldChild, Expression newChild)
 {
     Expression leftOperand = node.Left.Equals(oldChild) ? newChild : node.Left;
     Expression rightOperand = node.Right.Equals(oldChild) ? newChild : node.Right;
     return node.Update(leftOperand, node.Conversion, rightOperand);
 }
开发者ID:radamus,项目名称:OptimizableLINQ,代码行数:6,代码来源:TreeNodeReplacer.cs

示例7: VisitBinary

        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used 
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected override Expression VisitBinary(BinaryExpression node)
        {
            var newLeft = Visit(node.Left);
            var newRight = Visit(node.Right);

            if ((node.NodeType == ExpressionType.Equal)
                || (node.NodeType == ExpressionType.NotEqual))
            {
                var leftIsNull = BuildIsNullExpression(newLeft);
                var leftNullable = leftIsNull != null;

                var rightIsNull = BuildIsNullExpression(newRight);
                var rightNullable = rightIsNull != null;

                Type conversionResultTypeLeft;
                Type conversionResultTypeRight;

                var unwrappedConvertLeft = UnwrapConvertExpression(newLeft, out conversionResultTypeLeft);
                var unwrappedConvertRight = UnwrapConvertExpression(newRight, out conversionResultTypeRight);

                var leftUnary = unwrappedConvertLeft as UnaryExpression;
                var leftNegated = (leftUnary != null) && (leftUnary.NodeType == ExpressionType.Not);

                var rightUnary = unwrappedConvertRight as UnaryExpression;
                var rightNegated = (rightUnary != null) && (rightUnary.NodeType == ExpressionType.Not);

                var leftOperand
                    = leftNegated
                        ? conversionResultTypeLeft == null
                            ? leftUnary.Operand
                            : Expression.Convert(leftUnary.Operand, conversionResultTypeLeft)
                        : newLeft;

                var rightOperand
                    = rightNegated
                        ? conversionResultTypeRight == null
                            ? rightUnary.Operand
                            : Expression.Convert(rightUnary.Operand, conversionResultTypeRight)
                        : newRight;

                if (node.NodeType == ExpressionType.Equal)
                {
                    if (leftNullable && rightNullable)
                    {
                        return leftNegated == rightNegated
                            ? ExpandNullableEqualNullable(leftOperand, rightOperand, leftIsNull, rightIsNull)
                            : ExpandNegatedNullableEqualNullable(leftOperand, rightOperand, leftIsNull, rightIsNull);
                    }

                    if (leftNullable)
                    {
                        return leftNegated == rightNegated
                            ? ExpandNullableEqualNonNullable(leftOperand, rightOperand, leftIsNull)
                            : ExpandNegatedNullableEqualNonNullable(leftOperand, rightOperand, leftIsNull);
                    }

                    if (rightNullable)
                    {
                        return leftNegated == rightNegated
                            ? ExpandNonNullableEqualNullable(leftOperand, rightOperand, rightIsNull)
                            : ExpandNegatedNonNullableEqualNullable(leftOperand, rightOperand, rightIsNull);
                    }
                }

                if (node.NodeType == ExpressionType.NotEqual)
                {
                    if (leftNullable && rightNullable)
                    {
                        return leftNegated == rightNegated
                            ? ExpandNullableNotEqualNullable(leftOperand, rightOperand, leftIsNull, rightIsNull)
                            : ExpandNegatedNullableNotEqualNullable(leftOperand, rightOperand, leftIsNull, rightIsNull);
                    }

                    if (leftNullable)
                    {
                        return leftNegated == rightNegated
                            ? ExpandNullableNotEqualNonNullable(leftOperand, rightOperand, leftIsNull)
                            : ExpandNegatedNullableNotEqualNonNullable(leftOperand, rightOperand, leftIsNull);
                    }

                    if (rightNullable)
                    {
                        return leftNegated == rightNegated
                            ? ExpandNonNullableNotEqualNullable(leftOperand, rightOperand, rightIsNull)
                            : ExpandNegatedNonNullableNotEqualNullable(leftOperand, rightOperand, rightIsNull);
                    }
                }
            }

            return node.Update(newLeft, node.Conversion, newRight);
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:95,代码来源:RelationalNullsExpandingVisitor.cs

示例8: TryOptimize

        private Expression TryOptimize(
            BinaryExpression binaryExpression,
            ExpressionType equalityType,
            Func<AliasExpression, List<Expression>, Expression> inExpressionFactory)
        {
            var leftExpression = Visit(binaryExpression.Left);
            var rightExpression = Visit(binaryExpression.Right);

            Expression leftNonColumnExpression, rightNonColumnExpression;
            IReadOnlyList<Expression> leftInValues = null;
            IReadOnlyList<Expression> rightInValues = null;

            var leftAliasExpression
                = MatchEqualityExpression(
                    leftExpression,
                    equalityType,
                    out leftNonColumnExpression);

            var rightAliasExpression
                = MatchEqualityExpression(
                    rightExpression,
                    equalityType,
                    out rightNonColumnExpression);

            if (leftAliasExpression == null)
            {
                leftAliasExpression = equalityType == ExpressionType.Equal
                    ? MatchInExpression(leftExpression, ref leftInValues)
                    : MatchNotInExpression(leftExpression, ref leftInValues);
            }

            if (rightAliasExpression == null)
            {
                rightAliasExpression = equalityType == ExpressionType.Equal
                    ? MatchInExpression(rightExpression, ref rightInValues)
                    : MatchNotInExpression(rightExpression, ref rightInValues);
            }

            if (leftAliasExpression.HasColumnExpression()
                && rightAliasExpression.HasColumnExpression()
                && leftAliasExpression.TryGetColumnExpression().Equals(rightAliasExpression.TryGetColumnExpression()))
            {
                var inArguments = new List<Expression>();
                if (leftNonColumnExpression != null)
                {
                    inArguments.Add(leftNonColumnExpression);
                }

                if (leftInValues != null)
                {
                    inArguments.AddRange(leftInValues);
                }

                if (rightNonColumnExpression != null)
                {
                    inArguments.Add(rightNonColumnExpression);
                }

                if (rightInValues != null)
                {
                    inArguments.AddRange(rightInValues);
                }

                return inExpressionFactory(
                    leftAliasExpression,
                    inArguments);
            }

            if ((leftExpression != binaryExpression.Left)
                || (rightExpression != binaryExpression.Right))
            {
                return binaryExpression.Update(leftExpression, binaryExpression.Conversion, rightExpression);
            }

            return null;
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:76,代码来源:EqualityPredicateInExpressionOptimizer.cs


注:本文中的System.Linq.Expressions.BinaryExpression.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。