Ejemplo n.º 1
0
        private Expression Prepare(Expression cachedExpression, ParameterBag parameters)
        {
            Expression result;

            if (parameters.Any())
            {
                var visitor = new ConstantExpressionReplacementVisitor(parameters);
                result = visitor.Visit(cachedExpression);
            }
            else
            {
                result = cachedExpression;
            }
            // perform null-propagation if this feature is enabled.
            if (_configurationProvider.EnableNullPropagationForQueryMapping)
            {
                var nullVisitor = new NullsafeQueryRewriter();
                return(nullVisitor.Visit(result));
            }
            return(result);
        }
Ejemplo n.º 2
0
        private Expression Prepare(Expression cachedExpression, object parameters)
        {
            Expression result;

            if (parameters != null)
            {
                var visitor = ParameterExpressionVisitor.Create(parameters);
                result = visitor.Visit(cachedExpression);
            }
            else
            {
                result = cachedExpression;
            }
            // perform null-propagation if this feature is enabled.
            if (_configurationProvider.EnableNullPropagationForQueryMapping)
            {
                var nullVisitor = new NullsafeQueryRewriter();
                return(nullVisitor.Visit(result));
            }
            return(result);
        }
Ejemplo n.º 3
0
        public Expression CreateMapExpression(Type sourceType, Type destinationType, IDictionary <string, object> parameters = null, params MemberInfo[] membersToExpand)
        {
            parameters = parameters ?? new Dictionary <string, object>();

            var cachedExpression = _expressionCache.GetOrAdd(new ExpressionRequest(sourceType, destinationType, membersToExpand, null));

            Expression x = cachedExpression;

            if (parameters.Any())
            {
                var visitor = new ConstantExpressionReplacementVisitor(parameters);
                x = visitor.Visit(cachedExpression);
            }

            // perform null-propagation if this feature is enabled.
            if (_configurationProvider.EnableNullPropagationForQueryMapping)
            {
                var nullVisitor = new NullsafeQueryRewriter();
                return(nullVisitor.Visit(x));
            }
            return(x);
        }
Ejemplo n.º 4
0
        public LambdaExpression[] GetMapExpression(Type sourceType, Type destinationType, object parameters, MemberInfo[] membersToExpand)
        {
            var expressionRequest = new ExpressionRequest(
                sourceType ?? throw new ArgumentNullException(nameof(sourceType)),
                destinationType ?? throw new ArgumentNullException(nameof(destinationType)),
                membersToExpand ?? throw new ArgumentNullException(nameof(membersToExpand)),
                null);
            var cachedExpressions = _expressionCache.GetOrAdd(expressionRequest);

            return(Array.ConvertAll(cachedExpressions, Prepare));

            LambdaExpression Prepare(Expression cachedExpression)
            {
                var result = parameters == null ? cachedExpression : ParameterExpressionVisitor.SetParameters(parameters, cachedExpression);

                return((LambdaExpression)(_configurationProvider.EnableNullPropagationForQueryMapping ? NullsafeQueryRewriter.NullCheck(result) : result));
            }
        }