Lightweight and fast object mapper, which creates methods for mapping at the compile time.
There are a lot of things that are not implemented yet or some code can give you unexpected result, so use this package at your own risk.
- PowerShell:
Install-Package SunMapper
-- OR --
- Add reference to the project file:
<PackageReference Include="SunMapper"/>
You can find other ways for installing here.
Add MapTo attribute to a model you want to get data from:
using SunMapper.Common.Attributes;
[MapTo(typeof(UserGetDto))]
public class User {
public int Id { get; set; }
public string Name { get; set; }
public string PasswordHash { get; set; }
}
public class UserGetDto {
public string Name { get; set; }
}Bunch stuff will be generated under the hood, that's why you can use extension method TryMapTo of User:
var user = new User { Id = 0, Name = "User", PasswordHash = "Hash" };
if (user.TryMapTo(out UserGetDto dto)) {
// working with dto
}You can map only public properties with { get; set } methods and the same type.
For comfortable using library, this things should be implemented:
- Mapping profiles
- Custom type conversation
- Upselling architecture
- Support of popular libraries such as FluentValidation
- ASP.NET Support
- Readable generated code