copy chosen properties to object of other type

前端 未结 2 868
旧时难觅i
旧时难觅i 2021-01-28 06:06

I need to copy properties of one object to another, both objects can be of different type, can have properties of same name. These property can also be of complex type.

2条回答
  •  广开言路
    2021-01-28 06:24

    Use AutoMapper and ignore the members you don't want to map.

    config.CreateMap()
        .ForMember(d => d.Name, o => o.MapFrom(s => s.FullName))
        .ForMember(d => d.Age, o => o.Ignore());
    

提交回复
热议问题