public override Expression MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap,
                                          IMemberMap memberMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
 {
     if (destExpression.Type.IsInterface())
     {
         var listType = typeof(IList <>).MakeGenericType(ElementTypeHelper.GetElementType(destExpression.Type));
         destExpression = Expression.Convert(destExpression, listType);
     }
     return(CollectionMapperExpressionFactory.MapCollectionExpression(configurationProvider, profileMap, memberMap, sourceExpression,
                                                                      destExpression, contextExpression, typeof(List <>), CollectionMapperExpressionFactory.MapItemExpr));
 }
        public Expression MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap,
                                        IMemberMap memberMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
        {
            var listType = typeof(List <>).MakeGenericType(ElementTypeHelper.GetElementType(destExpression.Type));
            var list     = CollectionMapperExpressionFactory.MapCollectionExpression(configurationProvider, profileMap, memberMap, sourceExpression, Expression.Default(listType), contextExpression, typeof(List <>), CollectionMapperExpressionFactory.MapItemExpr);
            var dest     = Expression.Variable(listType, "dest");

            var ctor = destExpression.Type.GetDeclaredConstructors()
                       .First(ci => ci.GetParameters().Length == 1 && ci.GetParameters()[0].ParameterType.IsAssignableFrom(dest.Type));

            return(Expression.Block(new[] { dest },
                                    Expression.Assign(dest, list),
                                    Expression.Condition(Expression.NotEqual(dest, Expression.Default(listType)),
                                                         Expression.New(ctor, dest),
                                                         Expression.Default(destExpression.Type))));
        }
        public Expression MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap,
                                        IMemberMap memberMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
        {
            var dictionaryTypes = ElementTypeHelper.GetElementTypes(destExpression.Type, ElementTypeFlags.BreakKeyValuePair);
            var dictType        = typeof(Dictionary <,>).MakeGenericType(dictionaryTypes);
            var dict            = CollectionMapperExpressionFactory.MapCollectionExpression(configurationProvider, profileMap, memberMap, sourceExpression, Expression.Default(dictType), contextExpression, typeof(Dictionary <,>), CollectionMapperExpressionFactory.MapKeyPairValueExpr);
            var dest            = Expression.Variable(dictType, "dest");

            var readOnlyDictType = destExpression.Type.IsInterface
                ? typeof(ReadOnlyDictionary <,>).MakeGenericType(dictionaryTypes)
                : destExpression.Type;

            var ctor = readOnlyDictType.GetDeclaredConstructors()
                       .First(ci => ci.GetParameters().Length == 1 && ci.GetParameters()[0].ParameterType.IsAssignableFrom(dest.Type));

            return(Expression.Block(new[] { dest },
                                    Expression.Assign(dest, dict),
                                    Expression.Condition(Expression.NotEqual(dest, Expression.Default(dictType)),
                                                         ExpressionFactory.ToType(Expression.New(ctor, dest), destExpression.Type),
                                                         Expression.Default(destExpression.Type))));
        }
Exemplo n.º 4
0
 public override Expression MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap,
                                          IMemberMap memberMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
 => CollectionMapperExpressionFactory.MapCollectionExpression(configurationProvider, profileMap, memberMap, sourceExpression, destExpression, contextExpression, typeof(List <>), CollectionMapperExpressionFactory.MapItemExpr);
Exemplo n.º 5
0
 public Expression MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap,
                                 IMemberMap memberMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
 => CollectionMapperExpressionFactory.MapCollectionExpression(configurationProvider, profileMap, memberMap,
                                                              Expression.Call(MembersDictionaryMethodInfo, sourceExpression, Expression.Constant(profileMap)), destExpression, contextExpression, typeof(Dictionary <,>),
                                                              CollectionMapperExpressionFactory.MapKeyPairValueExpr);