首页 > 代码库 > AutoMapper新语法

AutoMapper新语法

var mapper = config.CreateMapper();
// or
IMapper mapper = new Mapper(config);
var dest = mapper.Map<Source, Dest>(new Source());

 Mapper.Initialize(cfg => {
                    cfg.CreateMap<QuoteOutputModel, QuoteSnapshot>()
                        .ForMember(dest => dest.Quote, opt => opt.MapFrom(src =http://www.mamicode.com/> src.CarrierQuotes))
                        .ForMember(dest => dest.Quote, opt => opt.MapFrom(src =http://www.mamicode.com/> src.CarrierQuotes)
                        );
                });

var config = new MapperConfiguration(cfg => {
    cfg.AddProfile<AppProfile>();
    cfg.CreateMap<Source, Dest>();
});

AutoMapper新语法