[英]Automapper mapping generic types
I have 2 generic types that I need to map 我有2种通用类型需要映射
public class A<T>
{
public List<T> Results { get; set; }
public int PropertyA { get; set; }
public int PropertyB { get; set; }
}
and 和
public class B<T>
{
public List<T> ResultContent { get; set; }
public int PropertyC { get; set; }
}
I've tried to map A to B using automapper as follows: 我尝试使用自动映射器将A映射到B,如下所示:
Mapper.CreateMap(typeof(A<>),typeof(B<>))
.ForMember("ResultContent", f => f.MapFrom("Results"))
.ForMember("PropertyC", f => f.MapFrom(?????))
It works fine for the ResultContent
property. 对于
ResultContent
属性,它工作正常。 However, the issue is that B.PropertyC is a sum of properties A.PropertyA and A.PropertyB. 但是,问题在于B.PropertyC是属性A.PropertyA和A.PropertyB的总和。 Is it possible to compute mapping of properties for generic types?
是否可以计算泛型类型的属性映射?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.