首页 > 移动平台 > 详细

AutoMapper 9.0 简单用法

时间:2020-04-14 00:18:42      阅读:158      评论:0      收藏:0      [点我收藏+]
AutoMapper.MapperConfiguration cfg = new AutoMapper.MapperConfiguration(q => { q.CreateMap(typeof(DTO), typeof(Model)); q.CreateMap(typeof(AddressDTO), typeof(AddressModel)); });
DTO o = new DTO() { userName = "AAA" };
o.address = new AddressDTO() { country = "China" };
var m= cfg.CreateMapper().Map<Model>(o);
Console.WriteLine(m.address?.country);

技术分享图片

    public class DTO
    {
        public string userName { set; get; }
        public string age { set; get; }
        public string job { set; get; }
        public AddressDTO address { set; get; }
    }


    public class AddressDTO
    {
        public string country { set; get; }
        public string province { set; get; }
    }
    // Model
    public class Model
    {
        public string userName { set; get; }
        public string age { set; get; }
        public string job { set; get; }
        public AddressModel address { set; get; }
    }
    public class AddressModel
    {
        public string country { set; get; }
        public string province { set; get; }
    }

 

AutoMapper 9.0 简单用法

原文:https://www.cnblogs.com/honk/p/12695087.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!