Пример #1
0
        /// <summary>
        /// 左辺か右辺のいずれかがnullの場合の比較
        /// </summary>
        private DynamicMetaObject FallbackOnNull(DynamicMetaObject left, DynamicMetaObject right)
        {
            bool       value    = this.Operation == ExpressionType.Equal;
            Expression restExpr = null;

            if (left.Value == null && right.Value == null)
            {
                restExpr = Expression.And(
                    BinderHelper.IsNull(left.Expression),
                    BinderHelper.IsNull(right.Expression));
            }
            else if (left.Value == null)
            {
                value   ^= true;
                restExpr = Expression.AndAlso(
                    BinderHelper.IsNull(left.Expression),
                    BinderHelper.IsNotNull(right.Expression));
            }
            else
            {
                value   ^= true;
                restExpr = Expression.AndAlso(
                    BinderHelper.IsNull(right.Expression),
                    BinderHelper.IsNotNull(left.Expression));
            }
            var expr = BinderHelper.Wrap(Expression.Constant(value), this.ReturnType);
            var rest = BindingRestrictions.GetExpressionRestriction(restExpr);

            return(new DynamicMetaObject(expr, rest));
        }
Пример #2
0
        public override DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject left, DynamicMetaObject right, DynamicMetaObject errorSuggestion)
        {
            Expression          expr;
            BindingRestrictions rest;

            if (left.Value == null)
            {
                expr = BinderHelper.Wrap(right.Expression, this.ReturnType);
                rest = BindingRestrictions.GetExpressionRestriction(BinderHelper.IsNull(left.Expression));
            }
            else if (left.LimitType == typeof(bool))
            {
                expr = BinderHelper.Wrap(
                    Expression.Condition(BinderHelper.Wrap(left.Expression, typeof(bool)), left.Expression, right.Expression),
                    this.ReturnType);
                rest = BindingRestrictions.GetTypeRestriction(left.Expression, typeof(bool));
            }
            else
            {
                expr = BinderHelper.Wrap(left.Expression, this.ReturnType);
                rest = BindingRestrictions.GetExpressionRestriction(
                    Expression.AndAlso(
                        BinderHelper.IsNotNull(left.Expression),
                        Expression.Not(Expression.TypeIs(left.Expression, typeof(bool)))));
            }
            return(new DynamicMetaObject(expr, rest));
        }
Пример #3
0
        public override DynamicMetaObject FallbackUnaryOperation(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
        {
            Expression          boolExpr;
            BindingRestrictions rest;

            if (target.Value == null)
            {
                boolExpr = Expression.Constant(true);
                rest     = BindingRestrictions.GetExpressionRestriction(BinderHelper.IsNull(target.Expression));
            }
            else if (target.LimitType == typeof(bool))
            {
                boolExpr = Expression.Not(BinderHelper.Wrap(target.Expression, typeof(bool)));
                rest     = BindingRestrictions.GetTypeRestriction(target.Expression, typeof(bool));
            }
            else
            {
                boolExpr = Expression.Constant(false);
                rest     = BindingRestrictions.GetExpressionRestriction(
                    Expression.AndAlso(
                        BinderHelper.IsNotNull(target.Expression),
                        Expression.Not(Expression.TypeIs(target.Expression, typeof(bool)))));
            }
            var expr = BinderHelper.Wrap(boolExpr, this.ReturnType);

            return(new DynamicMetaObject(expr, rest));
        }
Пример #4
0
        /// <summary>
        /// 左辺、右辺のいずれかがnullで、もう一方はそうでない場合
        /// </summary>
        private DynamicMetaObject CompareEatherNull(DynamicMetaObject left, DynamicMetaObject right)
        {
            Contract.Requires <ArgumentException>(
                left.Value == null && right.Value != null ||
                left.Value != null && right.Value == null);

            bool?value = null;

            switch (this.Operation)
            {
            case ExpressionType.LessThan:
            case ExpressionType.LessThanOrEqual:
                value = false;
                break;

            case ExpressionType.GreaterThan:
            case ExpressionType.GreaterThanOrEqual:
                value = true;
                break;
            }
            Expression rest;
            bool       order;

            if (left.Value == null)
            {
                rest = Expression.AndAlso(
                    BinderHelper.IsNull(left.Expression),
                    BinderHelper.IsNotNull(right.Expression));
                order = true;
            }
            else
            {
                rest = Expression.AndAlso(
                    BinderHelper.IsNull(right.Expression),
                    BinderHelper.IsNotNull(left.Expression));
                order = false;
            }
            var expr = BinderHelper.Wrap(Expression.Constant(value ^ order), this.ReturnType);

            return(new DynamicMetaObject(expr, BindingRestrictions.GetExpressionRestriction(rest)));
        }