private static Expression GetDerivedTypeChildMapping(
            IObjectMappingData derivedTypeMappingData,
            Expression sourceValue,
            Expression targetValue)
        {
            var derivedTypeMapperData  = derivedTypeMappingData.MapperData;
            var declaredTypeMapperData = derivedTypeMappingData.DeclaredTypeMappingData.MapperData;

            var mappingValues = new MappingValues(
                sourceValue,
                targetValue,
                derivedTypeMapperData.EnumerableIndex);

            return(MappingFactory.GetChildMapping(
                       derivedTypeMappingData,
                       mappingValues,
                       declaredTypeMapperData.DataSourceIndex,
                       declaredTypeMapperData));
        }
        private Expression GetConfiguredToTargetDataSourceMappingOrNull(
            MappingCreationContext context,
            IConfiguredDataSource toTargetDataSource,
            bool isFirstDataSource)
        {
            if (context.MapperData.Context.IsForToTargetMapping)
            {
                return(null);
            }

            var toTargetContext = context.WithToTargetDataSource(toTargetDataSource);

            AddPopulationsAndCallbacks(toTargetContext);

            if (toTargetContext.MappingExpressions.None())
            {
                return(null);
            }

            context.UpdateFrom(toTargetContext, toTargetDataSource);

            var originalMapperData = context.MapperData;
            var isSequential       = toTargetDataSource.IsSequential;

            if (!isSequential)
            {
                toTargetContext.MappingExpressions.Add(
                    context.MapperData.GetReturnExpression(GetExpressionToReturn(toTargetContext)));
            }

            var toTargetMapping = MappingFactory.UseLocalToTargetDataSourceVariableIfAppropriate(
                originalMapperData,
                toTargetContext.MapperData,
                toTargetDataSource.Value,
                toTargetContext.GetMappingExpression());

            var hasCondition = isSequential
                ? toTargetDataSource.IsConditional
                : toTargetDataSource.HasConfiguredCondition;

            if (!hasCondition)
            {
                return(toTargetMapping);
            }

            Expression fallback;

            if (!isFirstDataSource || originalMapperData.TargetMember.IsComplex)
            {
                if (isSequential || !originalMapperData.TargetMemberIsEnumerableElement())
                {
                    return(Expression.IfThen(toTargetDataSource.Condition, toTargetMapping));
                }

                // Mapping a configured ToTargetInstead() data source to
                // a complex type enumerable element member; reset the
                // local instance variable to null to prevent reuse of a
                // previous element's mapping result:
                fallback = originalMapperData.GetTargetMemberDefault();
            }
            else
            {
                fallback = originalMapperData.LocalVariable.Type.GetEmptyInstanceCreation(
                    context.TargetMember.ElementType,
                    originalMapperData.EnumerablePopulationBuilder.TargetTypeHelper);
            }

            var assignFallback = originalMapperData.LocalVariable.AssignTo(fallback);

            return(Expression.IfThenElse(toTargetDataSource.Condition, toTargetMapping, assignFallback));
        }