99namespace AutoMapper . Mappers . Internal
1010{
1111 using static Expression ;
12- using static AutoMapper . Execution . ExpressionBuilder ;
12+ using static ExpressionBuilder ;
1313 using static ExpressionFactory ;
14+ using static ElementTypeHelper ;
1415
1516 public static class CollectionMapperExpressionFactory
1617 {
@@ -22,7 +23,7 @@ public static Expression MapCollectionExpression(IConfigurationProvider configur
2223 {
2324 var passedDestination = Variable ( destExpression . Type , "passedDestination" ) ;
2425 var newExpression = Variable ( passedDestination . Type , "collectionDestination" ) ;
25- var sourceElementType = ElementTypeHelper . GetElementType ( sourceExpression . Type ) ;
26+ var sourceElementType = GetElementType ( sourceExpression . Type ) ;
2627
2728 var itemExpr = mapItem ( configurationProvider , profileMap , sourceExpression . Type , passedDestination . Type ,
2829 contextExpression , out ParameterExpression itemParam ) ;
@@ -33,7 +34,7 @@ public static Expression MapCollectionExpression(IConfigurationProvider configur
3334 destinationCollectionType = typeof ( IList ) ;
3435 var addMethod = destinationCollectionType . GetDeclaredMethod ( "Add" ) ;
3536
36- Expression destination , createInstance , assignNewExpression ;
37+ Expression destination , assignNewExpression ;
3738
3839 UseDestinationValue ( ) ;
3940
@@ -46,7 +47,7 @@ public static Expression MapCollectionExpression(IConfigurationProvider configur
4647 Assign ( passedDestination , destExpression ) ,
4748 assignNewExpression ,
4849 Call ( destination , clearMethod ) ,
49- ToType ( mapExpr , createInstance . Type )
50+ mapExpr
5051 ) ;
5152 if ( propertyMap != null )
5253 return checkNull ;
@@ -61,14 +62,13 @@ void UseDestinationValue()
6162 {
6263 if ( propertyMap ? . UseDestinationValue == true )
6364 {
64- createInstance = passedDestination ;
6565 destination = passedDestination ;
6666 assignNewExpression = Empty ( ) ;
6767 }
6868 else
6969 {
7070 destination = newExpression ;
71- createInstance = passedDestination . Type . NewExpr ( ifInterfaceType ) ;
71+ Expression createInstance = passedDestination . Type . NewExpr ( ifInterfaceType ) ;
7272 var isReadOnly = Property ( ToType ( passedDestination , destinationCollectionType ) , "IsReadOnly" ) ;
7373 assignNewExpression = Assign ( newExpression ,
7474 Condition ( OrElse ( Equal ( passedDestination , Constant ( null ) ) , isReadOnly ) , ToType ( createInstance , passedDestination . Type ) , passedDestination ) ) ;
@@ -80,16 +80,16 @@ private static Expression NewExpr(this Type baseType, Type ifInterfaceType)
8080 {
8181 var newExpr = baseType . IsInterface ( )
8282 ? New (
83- ifInterfaceType . MakeGenericType ( ElementTypeHelper . GetElementTypes ( baseType ,
83+ ifInterfaceType . MakeGenericType ( GetElementTypes ( baseType ,
8484 ElementTypeFlags . BreakKeyValuePair ) ) )
8585 : DelegateFactory . GenerateConstructorExpression ( baseType ) ;
8686 return newExpr ;
8787 }
8888
8989 public static Expression MapItemExpr ( IConfigurationProvider configurationProvider , ProfileMap profileMap , Type sourceType , Type destType , Expression contextParam , out ParameterExpression itemParam )
9090 {
91- var sourceElementType = ElementTypeHelper . GetElementType ( sourceType ) ;
92- var destElementType = ElementTypeHelper . GetElementType ( destType ) ;
91+ var sourceElementType = GetElementType ( sourceType ) ;
92+ var destElementType = GetElementType ( destType ) ;
9393 itemParam = Parameter ( sourceElementType , "item" ) ;
9494
9595 var typePair = new TypePair ( sourceElementType , destElementType ) ;
@@ -100,8 +100,8 @@ public static Expression MapItemExpr(IConfigurationProvider configurationProvide
100100
101101 public static Expression MapKeyPairValueExpr ( IConfigurationProvider configurationProvider , ProfileMap profileMap , Type sourceType , Type destType , Expression contextParam , out ParameterExpression itemParam )
102102 {
103- var sourceElementTypes = ElementTypeHelper . GetElementTypes ( sourceType , ElementTypeFlags . BreakKeyValuePair ) ;
104- var destElementTypes = ElementTypeHelper . GetElementTypes ( destType , ElementTypeFlags . BreakKeyValuePair ) ;
103+ var sourceElementTypes = GetElementTypes ( sourceType , ElementTypeFlags . BreakKeyValuePair ) ;
104+ var destElementTypes = GetElementTypes ( destType , ElementTypeFlags . BreakKeyValuePair ) ;
105105
106106 var typePairKey = new TypePair ( sourceElementTypes [ 0 ] , destElementTypes [ 0 ] ) ;
107107 var typePairValue = new TypePair ( sourceElementTypes [ 1 ] , destElementTypes [ 1 ] ) ;
0 commit comments