我需要映射的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对象。