Tiny Mapper是一个.net平台的开源的对象映射组件,其它的对象映射组件好比AutoMapper有兴趣的能够去看,Tiny Mapper的github地址TinyMapper,Tiny Mapper最大的特色是快。git
首先能够经过NuGet下载安装:github
using Nelibur.ObjectMapper;
app
咱们分别定义两个对象:Person
,PersonDtO
工具
public class Person { public string Address { get; set; } public string Email { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public Guid Id { get; set; } public string NickName { get; set; } public DateTime CreateTime { get; set; } public string Phone { get; set; } } public class PersonDto { public Guid Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } public string Address { get; set; } public string NickName { get; set; } public string Phone { get; set; } }
Bind两个类:ui
TinyMapper.Bind<Person, PersonDto>();
.net
使用:code
var person = new Person { Id = Guid.NewGuid(), FirstName = "X", LastName = "Yy", Email = "24048@qq.com", Address = "Wall Street", CreateTime = DateTime.Now, NickName = "xiaoye", Phone = "13913541238", }; var personDto = TinyMapper.Map<PersonDto>(person); Console.WriteLine(personDto.Phone);
固然Bind还有重载的方法:对象
TinyMapper.Bind<Person, PersonDto>(config => { config.Ignore(x => x.Id);// 忽略Id config.Bind(x => x.FirstName, y => y.FirstName);// 指定映射名 });
更多的信息能够参考源站的文档文档