Mam następujący Dto obiektu:Automapper: Mapa pojedynczy obiekt z listy obiektów wewnątrz, aby tylko listy
public class PriceDto
{
public string Ticker {get; set;}
public double Open {get; set;}
public double Close {get; set;}
}
obiektów źródłowych:
public class RemoteData
{
public Security Security { get; set; }
public IList<Prices> Prices{ get; set; }
}
public class Security
{
public string Ticker {get; set;}
}
public class Prices
{
public double Open {get; set;}
public double Close {get; set;}
}
W rezultacie, chcę dostać kolekcję PriceDto
obiektów. Wiem, jak zmapować właściwość Ticker
. Ale nie mam pojęcia, jak mapować Prices
poprawnie:
CreateMap<RemoteData, PriceDto>()
.ForMember(d => d.Ticker, opt => opt.MapFrom(s => s.Security.Ticker));
Również Automapper nie można znaleźć konfigurację bo mam jeden RemoteData
, ale chcę uzyskać IList<PriceDto>
:
var json = await rangeUrl.GetJsonAsync<RemoteData>();
var dtos = _mapper.Map<IList<PriceDto>>(json);
uzyskać jak Aby obejść ten problem, utworzyłem mapę od Prices
do PriceDto
zamiast RemoteData
, a następnie po prostu użyj foreach
, aby przypisać Ticker
. Ale chcę podać, jak to zrobić z automapper.
Możliwy duplikat [Możliwe użycie AutoMappera do odwzorowania jednego obiektu na listę obiektów?] (Https://stackoverflow.com/questions/18096034/possible-to-use-automapper-to-map-one-object- to-list-of-objects) – Rhumborl