如何通过(源,目标)对获取AutoMapper定义?

时间:2015-12-09 07:37:49

标签: c# .net automapper

在AutoMapper中,我们可以使用投影来自定义这样的映射:

public class CalendarEventForm
{
    public DateTime EventDate { get; set; }
    public int EventHour { get; set; }
    public int EventMinute { get; set; }
    public string Title { get; set; }
}

public class CalendarEventForm
{
    public DateTime EventDate { get; set; }
    public int EventHour { get; set; }
    public int EventMinute { get; set; }
    public string Title { get; set; }
}

配置AutoMapper:

Mapper.CreateMap<CalendarEvent, CalendarEventForm>()
      .ForMember(dest => dest.EventDate, opt => opt.MapFrom(src => src.Date.Date))
      .ForMember(dest => dest.EventHour, opt => opt.MapFrom(src => src.Date.Hour))
      .ForMember(dest => dest.EventMinute, opt => opt.MapFrom(src => src.Date.Minute));

通过提供(source,destination)对,我们可以使用任何可用的API来反过来获取映射逻辑吗?

0 个答案:

没有答案