1
ここに私の問題がありますCondition
評価中の現在のプロパティの名前に行きたいと思います。私はAutomapperの以前のバージョンでこれを行うことができると信じています。助言がありますか?Automapper(5.1.1)ForAllMembers - 現在のプロパティの名前を取得
[TestFixture]
public class SandBox
{
public class MySource
{
public string Name { get; set; }
public int Count { get; set; }
}
public class MyDestination
{
public string Name { get; set; }
public int Count { get; set; }
}
public class SourceProfile : Profile
{
public SourceProfile()
{
this.CreateMap<MySource, MyDestination>()
.ForAllMembers(x => x.Condition((source, destination, arg3, arg4, resolutionContext) =>
{
// this will run twice (once for every property)
// but how can I find out, what the current property is?
return true;
}));
}
}
public SandBox()
{
Mapper.Initialize(x =>
{
x.AddProfile(new SourceProfile());
});
}
[Test]
public void Run()
{
var s = new MySource { Name = "X", Count = 42 };
var r = Mapper.Map<MyDestination>(s);
Assert.AreEqual(s.Name, r.Name);
}
}
は素晴らしい仕事、ありがとう! – Pelle