public interface ISource
{
string Name { get; set; }
int Age { get; set; }
}
public interface ITarget
{
string Name { get; set; }
int Age { get; set; }
}
public class Source : ISource
{
public string Name { get; set; }
public int Age { get; set; }
}
public class Target : ITarget
{
public string Name { get; set; }
public int Age { get; set; }
}
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap().As();
});
var mapper = config.CreateMapper();
var source = new Source { Name = "Tom", Age = 20 };
var target = mapper.Map(source);
这样,源接口中的数据将被映射到目标接口中,并返回目标接口的实现类对象。