示例#1
0
        private static bool HasUnconditionalDerivedTargetTypeMapping(
            IEnumerable <DerivedTypePair> derivedTypePairs,
            IMemberMapperData declaredTypeMapperData,
            out Type unconditionalDerivedTargetType,
            out TypePairGroup[] groupedTypePairs)
        {
            groupedTypePairs = derivedTypePairs
                               .GroupBy(tp => tp.DerivedTargetType)
                               .Project(group => new TypePairGroup(group))
                               .OrderBy(tp => tp.DerivedTargetType, MostToLeastDerived)
                               .ToArray();

            var unconditionalTypePairs = groupedTypePairs
                                         .Filter(tpg => tpg.TypePairs.None(tp => tp.HasConfiguredCondition));

            foreach (var unconditionalTypePair in unconditionalTypePairs)
            {
                var typePairsCondition = declaredTypeMapperData
                                         .GetTargetValidCheckOrNull(unconditionalTypePair.DerivedTargetType);

                if (typePairsCondition == null)
                {
                    unconditionalDerivedTargetType = unconditionalTypePair.DerivedTargetType;
                    return(true);
                }
            }

            unconditionalDerivedTargetType = null;
            return(false);
        }
示例#2
0
        private static Expression GetTypePairCondition(DerivedTypePair derivedTypePair, IMemberMapperData declaredTypeMapperData)
        {
            var condition = declaredTypeMapperData.GetTargetValidCheckOrNull(derivedTypePair.DerivedTargetType);

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

            var pairCondition = derivedTypePair.GetConditionOrNull(declaredTypeMapperData);

            return((condition != null) ? AndAlso(pairCondition, condition) : pairCondition);
        }
示例#3
0
        private static Expression AppendTargetValidCheckIfAppropriate(
            Expression condition,
            Type targetType,
            IMemberMapperData mapperData)
        {
            if (targetType == mapperData.TargetType)
            {
                return(condition);
            }

            var targetIsValid = mapperData.GetTargetValidCheckOrNull(targetType);

            if (targetIsValid == null)
            {
                return(condition);
            }

            condition = AndAlso(condition, targetIsValid);

            return(condition);
        }