private void ThrowIfRedundantSourceMember(ConfiguredLambdaInfo valueLambdaInfo, QualifiedMember targetMember)
        {
            if (!valueLambdaInfo.TryGetSourceMember(out var sourceMemberLambda))
            {
                return;
            }

            var mappingData = _configInfo.ToMappingData <TSource, TTarget>();

            var targetMemberMapperData  = new ChildMemberMapperData(targetMember, mappingData.MapperData);
            var targetMemberMappingData = mappingData.GetChildMappingData(targetMemberMapperData);
            var bestSourceMemberMatch   = SourceMemberMatcher.GetMatchFor(targetMemberMappingData);

            if (!bestSourceMemberMatch.IsUseable)
            {
                return;
            }

            var configuredSourceMember = sourceMemberLambda.ToSourceMember(MapperContext);

            if (!bestSourceMemberMatch.SourceMember.Matches(configuredSourceMember))
            {
                return;
            }

            throw new MappingConfigurationException(string.Format(
                                                        CultureInfo.InvariantCulture,
                                                        "Source member {0} will automatically be mapped to target {1} {2}, " +
                                                        "and does not need to be configured",
                                                        GetSourceMemberDescription(configuredSourceMember),
                                                        GetTargetMemberType(targetMember),
                                                        targetMember.GetFriendlyTargetPath(_configInfo)));
        }
Пример #2
0
        private void ThrowIfRedundantSourceMember(ConfiguredLambdaInfo valueLambdaInfo, QualifiedMember targetMember)
        {
            if (!valueLambdaInfo.IsSourceMember(out var sourceMemberLambda))
            {
                return;
            }

            var mappingData = _configInfo.ToMappingData <TSource, TTarget>();

            var targetMemberMapperData   = new ChildMemberMapperData(targetMember, mappingData.MapperData);
            var targetMemberMappingData  = mappingData.GetChildMappingData(targetMemberMapperData);
            var bestMatchingSourceMember = SourceMemberMatcher.GetMatchFor(targetMemberMappingData, out _);

            if (bestMatchingSourceMember == null)
            {
                return;
            }

            var sourceMember = sourceMemberLambda.ToSourceMember(MapperContext);

            if (!bestMatchingSourceMember.Matches(sourceMember))
            {
                return;
            }

            var targetMemberType = (targetMember.LeafMember.MemberType == MemberType.ConstructorParameter)
                ? "constructor parameter"
                : "member";

            throw new MappingConfigurationException(string.Format(
                                                        CultureInfo.InvariantCulture,
                                                        "Source member {0} will automatically be mapped to target {1} {2}, " +
                                                        "and does not need to be configured",
                                                        GetSourceMemberDescription(sourceMember),
                                                        targetMemberType,
                                                        targetMember.GetFriendlyTargetPath(_configInfo)));
        }