예제 #1
0
        public Expression NewExpression(Expression instanceParameter)
        {
            var parameters = CtorParams.Select(map =>
            {
                var result = new ExpressionResolutionResult(instanceParameter, Ctor.DeclaringType);

                var matchingExpressionConverter =
                    ExpressionResultConverters.FirstOrDefault(c => c.CanGetExpressionResolutionResult(result, map));

                result = matchingExpressionConverter?.GetExpressionResolutionResult(result, map)
                         ?? throw new Exception("Can't resolve this to Queryable Expression");

                return(result);
            });

            return(New(Ctor, parameters.Select(p => p.ResolutionExpression)));
        }
예제 #2
0
        private static ExpressionResolutionResult ResolveExpression(PropertyMap propertyMap, Type currentType,
                                                                    Expression instanceParameter)
        {
            var result = new ExpressionResolutionResult(instanceParameter, currentType);

            foreach (var resolver in propertyMap.GetSourceValueResolvers())
            {
                var matchingExpressionConverter =
                    ExpressionResultConverters.FirstOrDefault(c => c.CanGetExpressionResolutionResult(result, resolver));
                if (matchingExpressionConverter == null)
                {
                    throw new Exception("Can't resolve this to Queryable Expression");
                }
                result = matchingExpressionConverter.GetExpressionResolutionResult(result, propertyMap, resolver);
            }
            return(result);
        }
예제 #3
0
        public Expression NewExpression(Expression instanceParameter)
        {
            var parameters = CtorParams.Select(map =>
            {
                var result = new ExpressionResolutionResult(instanceParameter, Ctor.DeclaringType);

                var matchingExpressionConverter =
                    ExpressionResultConverters.FirstOrDefault(c => c.CanGetExpressionResolutionResult(result, map));

                result = matchingExpressionConverter?.GetExpressionResolutionResult(result, map)
                         ?? throw new AutoMapperMappingException($"Unable to generate the instantiation expression for the constructor {Ctor}: no expression could be mapped for constructor parameter '{map.Parameter}'.", null, TypeMap.Types);

                return(result);
            });

            return(New(Ctor, parameters.Select(p => p.ResolutionExpression)));
        }
예제 #4
0
        public Expression NewExpression(Expression instanceParameter)
        {
            var parameters = CtorParams.Select(map =>
            {
                var result = new ExpressionResolutionResult(instanceParameter, Ctor.DeclaringType);
                foreach (var resolver in map.SourceResolvers)
                {
                    var matchingExpressionConverter =
                        ExpressionResultConverters.FirstOrDefault(c => c.CanGetExpressionResolutionResult(result, resolver));
                    if (matchingExpressionConverter == null)
                    {
                        throw new Exception("Can't resolve this to Queryable Expression");
                    }
                    result = matchingExpressionConverter.GetExpressionResolutionResult(result, map, resolver);
                }
                return(result);
            });

            return(Expression.New(Ctor, parameters.Select(p => p.ResolutionExpression)));
        }
예제 #5
0
        private static MemberAssignment BindEnumerableExpression(IConfigurationProvider configuration, PropertyMap propertyMap, ExpressionRequest request, ExpressionResolutionResult result, IDictionary <ExpressionRequest, int> typePairCount, LetPropertyMaps letPropertyMaps)
        {
            var expression = result.ResolutionExpression;

            if (propertyMap.DestinationPropertyType != expression.Type)
            {
                var destinationListType    = ElementTypeHelper.GetElementType(propertyMap.DestinationPropertyType);
                var sourceListType         = ElementTypeHelper.GetElementType(propertyMap.SourceType);
                var listTypePair           = new ExpressionRequest(sourceListType, destinationListType, request.MembersToExpand, request);
                var transformedExpressions = configuration.ExpressionBuilder.CreateMapExpression(listTypePair, typePairCount, letPropertyMaps.New());
                if (transformedExpressions == null)
                {
                    return(null);
                }
                expression = transformedExpressions.Aggregate(expression, (source, lambda) => Select(source, lambda));
            }

            return(Expression.Bind(propertyMap.DestinationProperty, expression));
        }
예제 #6
0
 public MemberAssignment Build(IConfigurationProvider configuration, PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionRequest request, ExpressionResolutionResult result, IDictionary <ExpressionRequest, int> typePairCount, LetPropertyMaps letPropertyMaps)
 => BindEnumerableExpression(configuration, propertyMap, request, result, typePairCount, letPropertyMaps);
예제 #7
0
 public bool IsMatch(PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionResolutionResult result) =>
 propertyMap.DestinationPropertyType.IsGenericType &&
 propertyMap.DestinationPropertyType.GetGenericTypeDefinition() == typeof(IEnumerable <>) &&
 PrimitiveHelper.IsEnumerableType(propertyMap.SourceType);