private static void AddDeclaredSourceTypeMappings(
            IEnumerable <DerivedTypePair> derivedTypePairs,
            IObjectMappingData declaredTypeMappingData,
            ICollection <DerivedTypeMapping> derivedTypeMappings,
            out bool declaredTypeHasUnconditionalTypePair)
        {
            var declaredTypeMapperData = declaredTypeMappingData.MapperData;

            foreach (var derivedTypePair in derivedTypePairs)
            {
                var condition = GetTypePairCondition(derivedTypePair, declaredTypeMapperData);

                var derivedTypeMapping = MappingFactory.GetDerivedTypeMapping(
                    declaredTypeMappingData,
                    declaredTypeMapperData.SourceObject,
                    derivedTypePair.DerivedTargetType);

                var returnMappingResult = Expression.Return(declaredTypeMapperData.ReturnLabelTarget, derivedTypeMapping);
                declaredTypeHasUnconditionalTypePair = (condition == null);

                if (declaredTypeHasUnconditionalTypePair)
                {
                    derivedTypeMappings.Add(DerivedTypeMapping.Unconditional(derivedTypePair, returnMappingResult));
                    return;
                }

                var ifConditionThenMap = Expression.IfThen(condition, returnMappingResult);

                derivedTypeMappings.Add(DerivedTypeMapping.Conditional(derivedTypePair, ifConditionThenMap));
            }

            declaredTypeHasUnconditionalTypePair = false;
        }
        private static Expression GetReturnMappingResultExpression(
            IObjectMappingData mappingData,
            Expression typedVariable,
            Type targetType)
        {
            var mapping             = MappingFactory.GetDerivedTypeMapping(mappingData, typedVariable, targetType);
            var returnMappingResult = Expression.Return(mappingData.MapperData.ReturnLabelTarget, mapping);

            return(returnMappingResult);
        }