https://github.com/TinyMapper/TinyMapper
据说性能蛮高的,我没对比测试过。
NuGet安装下。
新增三个实体。
public class A { public string Name { get; set; } public string Address { get; set; } public int Age { get; set; } } public class B { public string Name { get; set; } public string Address { get; set; } public int Age { get; set; } } public class C { public string LastName { get; set; } public string Address { get; set; } public int Age { get; set; } }
界面里调用测试下
private void Button_Click(object sender, RoutedEventArgs e) { TinyMapper.Bind<A, B>(); A tmpA = new A() { Name="ly",Age=29,Address="ShangHai"}; B tmpB= TinyMapper.Map<A, B>(tmpA); TinyMapper.Bind<A, C>(p=> { p.Bind(s => s.Name, t => t.LastName); }); C tmpC = TinyMapper.Map<A, C>(tmpA); }
用法和AutoMapper差不多。