@@ -59,7 +59,6 @@ public EnumerablePopulationBuilder(ObjectMapperData omd)
5959
6060 _sourceElementParameter = _sourceElementType . GetOrCreateParameter ( ) ;
6161 var sourceElementId = GetIdentifierOrNull ( _sourceElementType , _sourceElementParameter , omd , typeIdsCache ) ;
62- string targetVariableName ;
6362
6463 if ( ElementTypesAreTheSame )
6564 {
@@ -68,7 +67,6 @@ public EnumerablePopulationBuilder(ObjectMapperData omd)
6867 GetSourceElementIdLambda ( _sourceElementParameter , sourceElementId , sourceElementId ) ;
6968
7069 _sourceVariableName = "source" + omd . SourceType . GetVariableNameInPascalCase ( ) ;
71- targetVariableName = "target" + omd . TargetType . GetVariableNameInPascalCase ( ) ;
7270 }
7371 else
7472 {
@@ -78,11 +76,10 @@ public EnumerablePopulationBuilder(ObjectMapperData omd)
7876 _targetElementIdLambda = GetTargetElementIdLambda ( targetElementParameter , targetElementId ) ;
7977
8078 _sourceVariableName = omd . SourceType . GetVariableNameInCamelCase ( ) ;
81- targetVariableName = omd . TargetType . GetVariableNameInCamelCase ( ) ;
8279 }
8380
8481 _discardExistingValues = omd . RuleSet . EnumerablePopulationStrategy . DiscardExistingValues ;
85- TargetVariable = GetTargetVariable ( targetVariableName ) ;
82+ TargetVariable = GetTargetVariable ( ) ;
8683
8784 _populationExpressions = new List < Expression > ( ) ;
8885 }
@@ -145,7 +142,7 @@ private static LambdaExpression GetTargetElementIdLambda(ParameterExpression tar
145142 targetElement ) ;
146143 }
147144
148- private ParameterExpression GetTargetVariable ( string name )
145+ private ParameterExpression GetTargetVariable ( )
149146 {
150147 Type targetVariableType ;
151148
@@ -164,6 +161,10 @@ private ParameterExpression GetTargetVariable(string name)
164161 targetVariableType = _omd . TargetType ;
165162 }
166163
164+ var name = ElementTypesAreTheSame
165+ ? "target" + targetVariableType . GetVariableNameInPascalCase ( )
166+ : targetVariableType . GetVariableNameInCamelCase ( ) ;
167+
167168 return Expression . Variable ( targetVariableType , name ) ;
168169 }
169170
@@ -358,8 +359,8 @@ public void AddNewItemsToTargetVariable(IObjectMappingData enumerableMappingData
358359 {
359360 loopExitCheck = Expression . Equal ( Counter , GetCountPropertyAccess ( ) ) ;
360361
361- if ( ElementTypesAreSimple ||
362- _sourceTypeHelper . ElementType . RuntimeTypeNeeded ( ) ||
362+ if ( ElementTypesAreSimple ||
363+ _sourceTypeHelper . ElementType . RuntimeTypeNeeded ( ) ||
363364 _targetElementType . RuntimeTypeNeeded ( ) )
364365 {
365366 populationLoopAdapter = exp => exp ;
0 commit comments