3
Im被AutoMapper语法卡住了。Automapper Map嵌套类中的成员
如何跳过嵌套类中的映射成员(通过条件字符串为空)? 林尝试下面的代码:
[TestMethod]
public void TestMethod4()
{
var a = new A { Nested = new NestedA { V = 1, S = "A" } };
var b = new B { Nested = new NestedB { V = 2, S = string.Empty } };
Mapper.CreateMap<B, A>();
Mapper.CreateMap<NestedB, NestedA>().ForMember(s => s.S, opt => opt.Condition(src => !string.IsNullOrWhiteSpace(src.S)));
var result = Mapper.Map(b, a);
Assert.AreEqual(2, result.Nested.V); // OK
Assert.AreEqual("A", result.Nested.S); // FAIL: S == null
}
感谢
即时通讯使用AutoMapper v2,并没有跳过选项。 – user1183964 2012-02-02 10:28:54