automaper9.0简单实用
using AutoMapper; using System; namespace AutomaperTest { class Program { static void Main(string[] args) { test1(); test2(); } static void test1() { //注册映射关系: var config = new MapperConfiguration(cfg => cfg.CreateMap<Deviceware, DevicewareDto>()); var mapper = config.CreateMapper(); var deviceware = new Deviceware(); deviceware.DeviceNumber = "hhhhh"; deviceware.SIMCCID = "jjjjjj"; var info = mapper.Map<Deviceware, DevicewareDto>(deviceware); Console.WriteLine($"{info.GetType()}--{info.SIMCCID}"); } static void test2() { //反向映射转换: var config = new MapperConfiguration(cfg => cfg.CreateMap<Order, OrderDto>().ReverseMap()); var mapper = config.CreateMapper(); var customer = new Customer { Name = "Bob" }; var order = new Order { Customer = customer, Total = 15.8m }; var orderDto = mapper.Map<Order, OrderDto>(order); orderDto.CustomerName = "Joe"; Order ddd = mapper.Map<OrderDto, Order>(orderDto, order); Console.WriteLine($"{ddd.Customer.Name}--{ddd.Total}"); } } }
posted on 2020-02-17 10:06 HOT SUMMER 阅读(271) 评论(0) 编辑 收藏 举报