예제 #1
0
        public static Expression GetDerivedTypeMapping(
            IObjectMappingData declaredTypeMappingData,
            Expression sourceValue,
            Type targetType,
            out IObjectMappingData derivedTypeMappingData)
        {
            derivedTypeMappingData = declaredTypeMappingData.WithDerivedTypes(sourceValue.Type, targetType);

            var declaredTypeMapperData = declaredTypeMappingData.MapperData;

            if (DerivedSourceTypeIsUnconditionallyIgnored(derivedTypeMappingData))
            {
                return(declaredTypeMapperData.TargetObject.GetConversionTo(targetType));
            }

            var targetValue = declaredTypeMapperData.TargetMember.IsReadable
                ? declaredTypeMapperData.TargetObject.GetConversionTo(targetType)
                : targetType.ToDefaultExpression();

            if (declaredTypeMappingData.IsRoot)
            {
                return(GetDerivedTypeRootMapping(derivedTypeMappingData, sourceValue, targetValue));
            }

            if (declaredTypeMapperData.TargetMemberIsEnumerableElement())
            {
                return(MappingFactory.GetElementMapping(derivedTypeMappingData, sourceValue, targetValue));
            }

            return(GetDerivedTypeChildMapping(derivedTypeMappingData, sourceValue, targetValue));
        }
예제 #2
0
 private static Expression GetElementMapping(
     Expression sourceElement,
     Expression targetElement,
     IObjectMappingData enumerableMappingData)
 {
     return(MappingFactory.GetElementMapping(sourceElement, targetElement, enumerableMappingData));
 }