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