public override Expression Visit(Expression node)
        {
            if (node == null || !IsNullable(node.Type))
            {
                return base.Visit(node);
            }

            var oldPropagationPoint = _propagationPoint;
            _propagationPoint = new PropagationPoint();

            var transformedExpression = base.Visit(node);

            if (_propagationPoint.IsActive)
            {
                var result = Expression.Variable(node.Type);

                transformedExpression = Expression.Block(
                    new[] { result },
                    Expression.Assign(result, Expression.Constant(null, node.Type)),
                    Expression.Assign(result, transformedExpression),
                    Expression.Label(_propagationPoint.Label),
                    result);
            }

            _propagationPoint = oldPropagationPoint;
            return transformedExpression;
        }
Ejemplo n.º 2
0
        public override Expression Visit(Expression node)
        {
            if (node == null || node.NodeType == ExpressionType.Lambda)
            {
                return(node);
            }

            if (!IsNullable(node.Type))
            {
                return(base.Visit(node));
            }

            var oldPropagationPoint = _propagationPoint;

            _propagationPoint = new PropagationPoint();

            var transformedExpression = base.Visit(node);

            if (_propagationPoint.IsActive)
            {
                var result = Expression.Variable(node.Type);

                transformedExpression = Expression.Block(
                    new[] { result },
                    Expression.Assign(result, Expression.Constant(null, node.Type)),
                    Expression.Assign(result, transformedExpression),
                    Expression.Label(_propagationPoint.Label),
                    result);
            }

            _propagationPoint = oldPropagationPoint;
            return(transformedExpression);
        }