private MappingConfigContinuation <TSource, TTarget> SetDerivedTargetType <TDerivedTarget>()
        {
            var derivedTypePair = DerivedTypePair
                                  .For <TDerivedSource, TTarget, TDerivedTarget>(_configInfo);

            _configInfo.MapperContext.UserConfigurations.DerivedTypes.Add(derivedTypePair);

            return(new MappingConfigContinuation <TSource, TTarget>(_configInfo));
        }
        /// <summary>
        /// Map the derived source type being configured to the derived target type specified by the type argument.
        /// </summary>
        /// <typeparam name="TDerivedTarget">
        /// The derived target type to create for the configured derived source type.
        /// </typeparam>
        /// <returns>
        /// A MappingConfigContinuation to enable further configuration of mappings from and to the source and
        /// target type being configured.
        /// </returns>
        public MappingConfigContinuation <TSource, TTarget> To <TDerivedTarget>()
            where TDerivedTarget : TTarget
        {
            var derivedTypePair = DerivedTypePair
                                  .For <TDerivedSource, TTarget, TDerivedTarget>(_configInfo);

            _configInfo.MapperContext.UserConfigurations.DerivedTypes.Add(derivedTypePair);

            return(new MappingConfigContinuation <TSource, TTarget>(_configInfo));
        }
Exemple #3
0
        private static Expression GetTypePairCondition(DerivedTypePair derivedTypePair, IMemberMapperData mapperData)
        {
            var condition = GetTargetValidCheckOrNull(derivedTypePair.DerivedTargetType, mapperData);

            if (!derivedTypePair.HasConfiguredCondition)
            {
                return(condition);
            }

            var pairCondition = derivedTypePair.GetConditionOrNull(mapperData);

            return((condition != null) ? Expression.AndAlso(pairCondition, condition) : pairCondition);
        }
Exemple #4
0
        private static Expression GetDerivedTypeSourceValue(
            DerivedTypePair derivedTypePair,
            IObjectMappingData declaredTypeMappingData,
            out Expression sourceValueCondition)
        {
            if (!derivedTypePair.IsImplementationPairing)
            {
                sourceValueCondition = null;
                return(declaredTypeMappingData.MapperData.SourceObject);
            }

            var implementationMappingData = declaredTypeMappingData
                                            .WithTypes(derivedTypePair.DerivedSourceType, derivedTypePair.DerivedTargetType);

            if (implementationMappingData.IsTargetConstructable())
            {
                sourceValueCondition = null;
                return(declaredTypeMappingData.MapperData.SourceObject);
            }

            // Derived Type is an implementation Type for an unconstructable target Type,
            // and is itself unconstructable; only way we get here is if a ToTarget data
            // source has been configured:
            var toTargetDataSource = implementationMappingData
                                     .GetToTargetDataSourceOrNullForTargetType();

            sourceValueCondition = toTargetDataSource.IsConditional
                ? toTargetDataSource.Condition.Replace(
                implementationMappingData.MapperData.SourceObject,
                declaredTypeMappingData.MapperData.SourceObject,
                ExpressionEvaluation.Equivalator)
                : null;

            return(toTargetDataSource.Value.Replace(
                       implementationMappingData.MapperData.SourceObject,
                       declaredTypeMappingData.MapperData.SourceObject,
                       ExpressionEvaluation.Equivalator));
        }
 public static DerivedTypeMapping Conditional(DerivedTypePair typePair, Expression mapping)
 => Conditional(typePair.DerivedSourceType, mapping);
 public static DerivedTypeMapping Unconditional(DerivedTypePair typePair, Expression mapping)
 => new DerivedTypeMapping(typePair.DerivedSourceType, mapping, isConditional: false);