AutoMapper generic mapping

前端 未结 2 1657
臣服心动
臣服心动 2021-02-18 17:42

I have searched on Stack Overflow and googled about it but I haven\'t been able to find any help or suggestion on this.

I have a class like the following which create a <

2条回答
  •  盖世英雄少女心
    2021-02-18 18:26

    According to the AutoMapper wiki:

    public class Source {
        public T Value { get; set; }
    }
    
    public class Destination {
        public T Value { get; set; }
    }
    
    // Create the mapping
    Mapper.CreateMap(typeof(Source<>), typeof(Destination<>));
    

    In your case this would be

    Mapper.CreateMap(typeof(PagedList<,>), typeof(PagedListViewModel<>));
    

提交回复
热议问题