Пример #1
0
 public Expression MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap,
                                 PropertyMap propertyMap, Expression sourceExpression, Expression destExpression,
                                 Expression contextExpression) =>
 TypeMapPlanBuilder.MapExpression(configurationProvider, profileMap,
                                  new TypePair(Nullable.GetUnderlyingType(sourceExpression.Type), destExpression.Type),
                                  Property(sourceExpression, sourceExpression.Type.GetDeclaredProperty("Value")),
                                  contextExpression,
                                  propertyMap,
                                  destExpression
                                  );
        public Expression CreateExpression(TypeMapPlanBuilder builder)
        {
            var valueResolverExpression = ResolveSource(builder.Source, builder.Context);
            var sourceType    = valueResolverExpression.Type;
            var resolvedValue = Variable(sourceType, "resolvedValue");

            return(Block(new[] { resolvedValue },
                         Assign(resolvedValue, valueResolverExpression),
                         builder.MapExpression(new TypePair(sourceType, DestinationType), resolvedValue)));
        }
Пример #3
0
        internal static Expression MapItemExpr(this TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider,
                                               PropertyMap propertyMap, Type sourceType, Type destType, ParameterExpression itemParam, Expression contextParam)
        {
            var sourceElementType = TypeHelper.GetElementType(sourceType);
            var destElementType   = TypeHelper.GetElementType(destType);

            var typePair = new TypePair(sourceElementType, destElementType);

            var itemExpr = TypeMapPlanBuilder.MapExpression(typeMapRegistry, configurationProvider, typePair, itemParam, contextParam, propertyMap);

            return(itemExpr);
        }
Пример #4
0
        internal static Expression MapItemExpr(this IConfigurationProvider configurationProvider, ProfileMap profileMap,
            PropertyMap propertyMap, Type sourceType, Type destType, Expression contextParam, out ParameterExpression itemParam)
        {
            var sourceElementType = TypeHelper.GetElementType(sourceType);
            var destElementType = TypeHelper.GetElementType(destType);
            itemParam = Parameter(sourceElementType, "item");

            var typePair = new TypePair(sourceElementType, destElementType);

            var itemExpr = TypeMapPlanBuilder.MapExpression(configurationProvider, profileMap, typePair, itemParam, contextParam, propertyMap);
            return ToType(itemExpr, destElementType);
        }
Пример #5
0
 public Expression MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap,
                                 PropertyMap propertyMap, Expression sourceExpression, Expression destExpression,
                                 Expression contextExpression) =>
 Condition(
     Property(sourceExpression, sourceExpression.Type.GetDeclaredProperty("HasValue")),
     TypeMapPlanBuilder.MapExpression(configurationProvider, profileMap,
                                      new TypePair(Nullable.GetUnderlyingType(sourceExpression.Type), destExpression.Type),
                                      Property(sourceExpression, sourceExpression.Type.GetDeclaredProperty("Value")),
                                      contextExpression,
                                      propertyMap,
                                      destExpression
                                      ),
     DelegateFactory.GenerateConstructorExpression(destExpression.Type, profileMap)
     );
Пример #6
0
        internal static Expression MapKeyPairValueExpr(this TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider,
                                                       PropertyMap propertyMap, Type sourceType, Type destType, ParameterExpression itemParam, Expression contextParam)
        {
            var sourceElementTypes = TypeHelper.GetElementTypes(sourceType, ElemntTypeFlags.BreakKeyValuePair);
            var destElementTypes   = TypeHelper.GetElementTypes(destType, ElemntTypeFlags.BreakKeyValuePair);

            var typePairKey   = new TypePair(sourceElementTypes[0], destElementTypes[0]);
            var typePairValue = new TypePair(sourceElementTypes[1], destElementTypes[1]);

            var sourceElementType = TypeHelper.GetElementType(sourceType);
            var destElementType   = TypeHelper.GetElementType(destType);

            var keyExpr   = TypeMapPlanBuilder.MapExpression(typeMapRegistry, configurationProvider, typePairKey, Expression.Property(itemParam, "Key"), contextParam, propertyMap);
            var valueExpr = TypeMapPlanBuilder.MapExpression(typeMapRegistry, configurationProvider, typePairValue, Expression.Property(itemParam, "Value"), contextParam, propertyMap);
            var keyPair   = Expression.New(destElementType.GetConstructors().First(), keyExpr, valueExpr);

            return(keyPair);
        }
Пример #7
0
        internal static Expression MapKeyPairValueExpr(this IConfigurationProvider configurationProvider,
            ProfileMap profileMap, PropertyMap propertyMap, Type sourceType, Type destType, Expression contextParam, out ParameterExpression itemParam)
        {
            var sourceElementTypes = TypeHelper.GetElementTypes(sourceType, ElementTypeFlags.BreakKeyValuePair);
            var destElementTypes = TypeHelper.GetElementTypes(destType, ElementTypeFlags.BreakKeyValuePair);

            var typePairKey = new TypePair(sourceElementTypes[0], destElementTypes[0]);
            var typePairValue = new TypePair(sourceElementTypes[1], destElementTypes[1]);

            var sourceElementType = typeof(KeyValuePair<,>).MakeGenericType(sourceElementTypes);
            itemParam = Parameter(sourceElementType, "item");
            var destElementType = typeof(KeyValuePair<,>).MakeGenericType(destElementTypes);

            var keyExpr = TypeMapPlanBuilder.MapExpression(configurationProvider, profileMap, typePairKey, Property(itemParam, "Key"), contextParam, propertyMap);
            var valueExpr = TypeMapPlanBuilder.MapExpression(configurationProvider, profileMap, typePairValue, Property(itemParam, "Value"), contextParam, propertyMap);
            var keyPair = New(destElementType.GetConstructors().First(), keyExpr, valueExpr);
            return keyPair;
        }