'FindTypeMapFor method not exists in AutoMapper 11
I am currently upgrading a web API that was developed on NET Core 5.0 and upgrading it to NET Core 6.0. When upgrading the NuGet AutoMapper package to version 11.0.1, I find that the FindTypeMapFor method does not exist in the ConfigurationProvider definition.
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;
}
How can I get the TypeMap object of a specific mapping?
How can I use FindTypeMapFor or some method that will replace it?
Solution 1:[1]
This was moved to the "Internal" object on AutoMapper 11.
Here's the new usage:
using AutoMapper.Internal;
Mapper.ConfigurationProvider.Internal().FindTypeMapFor
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Siphalor |