Automapper map泛型类型

时间:2016-09-21 02:50:29

标签: c# automapper automapper-4

我需要映射的2类数据 MainData

public class Data
{
    public Field<string> Results { get; set; }
    public Field<int> A { get; set; }
    public Field<int> B { get; set; }
}

public class Field<T>
{
 public string Label { get; set; }
 public T Value { get; set; }  
}

public class MainData{
 public string result {get; set; }
 public int a {get; set; }
 public int b {get; set; }
}

我尝试使用automapper将数据映射到 MainData ,如下所示:

Mapper.CreateMap(Data, MainData))
.ForMember(dest => dest.result, conf => conf.MapFrom(src => src.results.Value))
.ForMember(dest => dest.a, conf => conf.MapFrom(src => src.A.Value))
.ForMember(dest => dest.b, conf => conf.MapFrom(src => src.B.Value))

var destination = Mapper.Map<Data, MainData>(source);

永远不会将映射值映射到 desination 变量。我得到的只是新的MainData对象。

0 个答案:

没有答案