我目前正在升级一个在NetCore5.0上开发的web,并将其升级到NetCore6.0。当将NuGet AutoMapper包升级到11.0.1版本时,我发现ConfigurationProvider定义中不存在FindTypeMapFor方法。
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或某种替代它的方法?
发布于 2022-04-13 13:52:37
这被移到AutoMapper 11上的“内部”对象。
以下是新用法:
using AutoMapper.Internal;
Mapper.ConfigurationProvider.Internal().FindTypeMapForhttps://stackoverflow.com/questions/71375703
复制相似问题