AutoMapper 9.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);

AutoMapper 9.0 简单用法

    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 简单用法

上一篇:iOS 自动打包 IPA 相关


下一篇:安卓判断字符串是否相等