首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FindTypeMapFor方法在AutoMapper 11中不存在

FindTypeMapFor方法在AutoMapper 11中不存在
EN

Stack Overflow用户
提问于 2022-03-07 01:58:10
回答 1查看 668关注 0票数 1

我目前正在升级一个在NetCore5.0上开发的web,并将其升级到NetCore6.0。当将NuGet AutoMapper包升级到11.0.1版本时,我发现ConfigurationProvider定义中不存在FindTypeMapFor方法。

代码语言:javascript
复制
public Dictionary<string, PropertyMappingValue> GetPropertyMappingFromAutomapper<TSource, TDestination>(List<string> reverseOrderProperties) where TSource : class where TDestination : class
    {
        Dictionary<string, PropertyMappingValue> dictionaryPropertyMapping = new(StringComparer.OrdinalIgnoreCase);

        if (typeof(TSource).Equals(typeof(ForNotIncludeDto)) || typeof(TSource).Equals(typeof(ForNotSortingDto)) || typeof(TSource).Equals(typeof(ForNotDistinctDto)))
        {
            return dictionaryPropertyMapping;
        }

        TypeMap typeMap = this.Mapper.ConfigurationProvider.FindTypeMapFor<TSource, TDestination>();

        if (typeMap is null)
        {
            throw new Exception($"Cannot find exact property mapping instance " + $"for <{typeof(TSource)},{typeof(TDestination)}>");
        }

        List<PropertyMap> propertyMaps = typeMap.PropertyMaps.Where(x => x.Ignored == false).ToList();
        List<PathMap> pathMaps = typeMap.PathMaps.Where(x => x.Ignored == false).ToList();

        foreach (MemberInfo member in typeMap.SourceTypeDetails.AllMembers)
        {
            List<string> originPropertyMap = propertyMaps.Where(x => x.SourceMember is not null && x.SourceMember.Name.Equals(member.Name)).Select(x => x.DestinationName).ToList();

            if (originPropertyMap.Count.Equals(0))
            {
                originPropertyMap = pathMaps.Where(x => x.SourceMember is not null && x.SourceMember.Name.Equals(member.Name)).Select(x => x.DestinationName).ToList();
            }

            if (originPropertyMap.Count > 0)
            {
                dictionaryPropertyMapping.Add(member.Name, new PropertyMappingValue(originPropertyMap, reverseOrderProperties.Where(x => x.Equals(member.Name)).Any()));
            }
        }

        return dictionaryPropertyMapping;
    }

如何获得特定映射的TypeMap对象?

我如何使用FindTypeMapFor或某种替代它的方法?

EN

回答 1

Stack Overflow用户

发布于 2022-04-13 13:52:37

这被移到AutoMapper 11上的“内部”对象。

以下是新用法:

代码语言:javascript
复制
using AutoMapper.Internal;

Mapper.ConfigurationProvider.Internal().FindTypeMapFor
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71375703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档