I have a problem to map the properties using Automapper.
Mapping is for a destination type MyClass and source type IMyInterface. Here are a models.
Source type where ElectricPotential is struct of UnitsNet and concrete type on return for IProperty is Property which is internal class in another package:
public interface IMyInterface
{
IProperty<ElectricPotential?> NominalVoltage { get; set; }
}
Destination type where Units is my class to which I want to map:
public class MyClass : IMapFrom<IMyInterface>
{
IProperty<Units> NominalVoltage { get; set; }
public void MapFrom(Profile profile)
{
profile.CreateMap<IMyInterface, s>()
.ForMember(dest => dest.NominalVoltage,
opt => opt.MapFrom(src => src.NominalVoltage));
profile.CreateMap<ElectricPotential, Units>()
.ForMember(dest => dest.Unit, opt
=> opt.MapFrom(src => src.Unit.ToString()))
.ForMember(dest => dest.Value, opt
=> opt.MapFrom(src => src.Value));
}
}
Versions:
.NET 8
AutoMapper 12.0.0
MSA.BuildingBlocks.Mapping 0.1.1
I tried to map using this code:
public void MapFrom(Profile profile)
{
profile.CreateMap<IMyInterface, s>()
.ForMember(dest => dest.NominalVoltage,
opt => opt.MapFrom(src => src.NominalVoltage));
profile.CreateMap<ElectricPotential, Units>()
.ForMember(dest => dest.Unit, opt
=> opt.MapFrom(src => src.Unit.ToString()))
.ForMember(dest => dest.Value, opt
=> opt.MapFrom(src => src.Value));
}
But I receive
AutoMapper.AutoMapperMappingException: Error mapping types.
Mapping types:
IMyInterface-> MyClass
Type Map configuration:
IMyInterface-> MyClass
Destination Member:
NominalVoltage
---> AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
Mapping types:
Property`1 -> IProperty`1
Property`1[[System.Nullable`1[[UnitsNet.ElectricPotential, UnitsNet, Version=5.0.0.0, Culture=neutral, PublicKeyToken=f8601875a1f041da]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] -> IProperty`1[[S.Units, SapIntegration.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
I expect to map this struct. Because there are another type of structs from UnitsNet to map.