How to write a config to source generate a mapper for IReadOnlyCollection using Mapster?

240 Views Asked by At

How can I write a config to source generate a mapper from IReadOnlyCollection<POCO> to IReadOnlyCollection<DTO> using Mapster?

I have tried doing the following but it does not work.

public class MapsterConfiguration : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        config.NewConfig<IReadOnlyCollection<POCO>, IReadOnlyCollection<DTO>>()
            .GenerateMapper(MapType.Map | MapType.MapToTarget);
    }
}

but if I use IReadOnlyCollection as a property, it works

public class CollectionDTO
{
    public IReadOnlyCollection<DTO> MyProperty { get; set; }
}
config.NewConfig<CollectionPOCO, CollectionDTO>()
                .GenerateMapper(MapType.Map | MapType.MapToTarget);
0

There are 0 best solutions below