/// <summary> /// 自定义配置 /// </summary> public static void ConfigMap() { var customer = new CustomerVip { VIP = true }; Mapper.Initialize(cfg => cfg.CreateMap <CustomerVip, CustomerVipDTO>() .ForMember(cv => cv.VIP, m => m.MapFrom <VIPResolver>())); var customerDto = Mapper.Map <CustomerVip, CustomerVipDTO>(customer); }
/// <summary> /// 类型转换 /// </summary> public static void TypeMap() { var customer = new CustomerVip { VIP = true }; //Mapper.Initialize(cfg => cfg.CreateMap<CustomerVip, CustomerVipDTO>() // .ConvertUsing(s=>new CustomerVipDTO // { // VIP = s.VIP?"y":"n" // })); //var customerDto = Mapper.Map<CustomerVip, CustomerVipDTO>(customer); Mapper.Initialize(cfg => cfg.CreateMap <CustomerVip, CustomerVipDTO>() .ConvertUsing(new CustomTypeConverter())); var customerDtp2 = Mapper.Map <CustomerVip, CustomerVipDTO>(customer); }