4
我环顾四周,无法完全找到我的问题的答案。我要做的是有条件的映射目标对象(不是字段/属性,对象)。换句话说,这样的事情:AutoMapper - 条件映射
public class Source
{
public int Id {get; set;}
public string Flag {get; set;}
}
public class Destination
{
public int Id {get; set;}
}
var sources = new List<Source>
{
new Source{Flag = "V", Id = 1},
new Source{Flag = "B", Id = 2}
};
var destinations = Mapper.Map<List<Source>, List<Destination>>(sources);
destinations.Count.ShouldEqual(1);
destinations[0].Id.ShouldEqual(2);
有没有人知道如何配置类型映射?我正在寻找类似的东西:
Mapper.CreateMap<Source, Destination>()
.SkipIf(src => src.Flag != "B");
我只是没有看到任何东西似乎支持这一点的配置选项。任何帮助将非常感激!提前致谢。