System.Linq.Expressions.BinaryExpression.ReduceUserdefinedLifted C# (CSharp) Метод

ReduceUserdefinedLifted() приватный Метод

private ReduceUserdefinedLifted ( ) : Expression
Результат Expression
        internal Expression ReduceUserdefinedLifted()
        {
            Debug.Assert(IsLiftedLogical);

            ParameterExpression left = Parameter(Left.Type, "left");
            ParameterExpression right = Parameter(Right.Type, "right");
            string opName = NodeType == ExpressionType.AndAlso ? "op_False" : "op_True";
            MethodInfo opTrueFalse = TypeUtils.GetBooleanOperator(Method.DeclaringType, opName);
            Debug.Assert(opTrueFalse != null);

            return Block(
                new TrueReadOnlyCollection<ParameterExpression>(left),
                new TrueReadOnlyCollection<Expression>(
                    Assign(left, Left),
                    Condition(
                        Property(left, "HasValue"),
                        Condition(
                            Call(opTrueFalse, Call(left, "GetValueOrDefault", null)),
                            left,
                            Block(
                                new TrueReadOnlyCollection<ParameterExpression>(right),
                                new TrueReadOnlyCollection<Expression>(
                                    Assign(right, Right),
                                    Condition(
                                        Property(right, "HasValue"),
                                        Convert(
                                            Call(
                                                Method,
                                                Call(left, "GetValueOrDefault", null),
                                                Call(right, "GetValueOrDefault", null)
                                            ),
                                            Type
                                        ),
                                        Constant(null, Type)
                                    )
                                )
                            )
                        ),
                        Constant(null, Type)
                    )
                )
            );
        }
    }

Usage Example

Пример #1
0
        // CONSIDER: These could be called from the StackSpiller where we know whether the children contain any await
        //           expressions, thus needing a rewrite that keeps the short-circuiting behavior. We keep it here for
        //           the time being to avoid diverging the spiller too much from what we have in LINQ.

        internal static Expression ReduceLogical(BinaryExpression node)
        {
            if (node.Method != null && !node.get_IsLiftedLogical())
            {
                return ReduceLogicalMethod(node);
            }
            else if (node.Left.Type == typeof(bool?))
            {
                return ReduceLogicalLifted(node);
            }
            else if (node.get_IsLiftedLogical())
            {
                return node.ReduceUserdefinedLifted();
            }
            else
            {
                return ReduceLogicalUnlifted(node);
            }
        }