private static bool HasCompatibleSourceMember(IMemberMapperData mapperData)
 {
     return(mapperData.SourceMember.IsEnumerable &&
            mapperData.CanConvert(
                mapperData.SourceMember.GetElementMember().Type,
                mapperData.TargetMember.GetElementMember().Type));
 }
        private static bool HasCompatibleSourceMember(IMemberMapperData mapperData)
        {
            if (!mapperData.SourceMember.IsEnumerable)
            {
                return(false);
            }

            var sourceElementMember = mapperData.SourceMember.GetElementMember();
            var targetElementMember = mapperData.TargetMember.GetElementMember();

            if (mapperData.CanConvert(sourceElementMember.Type, targetElementMember.Type))
            {
                return(true);
            }

            if (!mapperData.MapperContext.UserConfigurations.HasMappingFactories)
            {
                return(false);
            }

            var queryContext = new QualifiedMemberContext(
                mapperData.RuleSet,
                sourceElementMember.Type,
                targetElementMember.Type,
                sourceElementMember,
                targetElementMember,
                mapperData,
                mapperData.MapperContext);

            return(ConfiguredMappingFactory.HasMappingFactories(queryContext));
        }
Exemple #3
0
            public static bool TryCreateFor(IMemberMapperData mapperData, ref MetaMemberPartBase metaMemberPart)
            {
                if (!mapperData.TargetMember.IsSimple)
                {
                    return(false);
                }

                if (!mapperData.CanConvert(typeof(bool), mapperData.TargetMember.Type))
                {
                    return(false);
                }

                metaMemberPart = new HasMetaMemberPart(mapperData);
                return(true);
            }
Exemple #4
0
        private static bool HasUseableSourceDictionary(IMemberMapperData mapperData)
        {
            if (!mapperData.SourceMemberIsStringKeyedDictionary(out var dictionarySourceMember))
            {
                return(false);
            }

            if (dictionarySourceMember.HasObjectEntries)
            {
                return(true);
            }

            var valueType = dictionarySourceMember.ValueType;

            Type targetType;

            if (mapperData.TargetMember.IsEnumerable)
            {
                if (valueType.IsEnumerable())
                {
                    return(true);
                }

                targetType = mapperData.TargetMember.ElementType;

                if ((valueType == targetType) || targetType.IsComplex())
                {
                    return(true);
                }
            }
            else
            {
                targetType = mapperData.TargetMember.Type;
            }

            return(mapperData.CanConvert(valueType, targetType));
        }
 private static bool TypesAreCompatible(Type sourceType, IMemberMapperData mapperData)
 => mapperData.CanConvert(sourceType, mapperData.TargetMember.Type);