This project has source generator that allows to generate constructor mappings without any business logic. Main use case is considered to be immutable models (records).
| Package | NuGet |
|---|---|
| MappingSourceGenerator |
- Extension methods
- Collections support (arrays,
List<T>and any interface implemented by them) - Enum support
- Nested mapping support
- Using of manual mapping for nested properties
For examples please check out src/MappingSourceGenerator.IntegrationTests project.
- Add package references to required packages
<PackageReference Include="MappingSourceGenerator" Version="0.1.16" PrivateAssets="all" ExcludeAssets="runtime" />- Create method definition for source generator. It should be
static partialmethod marked withMappingSourceGenerator.Markers.GenerateMappingAttributeinstatic partialclass.
public static partial class Mapper
{
[GenerateMapping]
public static partial Person2 Map(this Person1 person1);
}Feel free to create issues for bugs or feature requests. General improvement suggestions (e.g. regarding tests) are appreciated.