虽然这个问题现在已经很老了,但我认为回答这个问题会很有用,因为我花了很多时间试图让配置文件工作。
虽然有一堆的方法来配置配置文件,似乎有什么我能得到它的工作的唯一办法如下:
public class ExampleProfile : Profile
{
protected override void Configure()
{
ReplaceMemberName("Z", "A");
CreateMap<Source, Destination>(); // Notice this is CreateMap, NOT Mapper.CreateMap...
}
public override string ProfileName
{
get { return this.GetType().Name; }
}
}
然后,设置配置文件在你的配置:
Mapper.Initialize(cfg => cfg.AddProfile<ExampleProfile>());
由于源和目标类如下:
public class Source
{
public string Zabc { get; set; }
}
public class Destination
{
public string Aabc { get; set; }
}
这个现在应该WOR k:
var source = new Source { Zabc = "source" };
var dest = Mapper.Map<Destination>(source);
Assert.AreEqual(source.Zabc, dest.Aabc);
这是一个很好的问题,但时间过去了2016我仍然无法找到答案。这个CreateProfile()方法似乎什么都不做。 – Xinan