This repository contains a collection of examples demonstrating how to use Riok.Mapperly, a high-performance .NET source generator for object mapping.
Mapperly creates the mapping code at build time, which means there is no runtime overhead and the generated code is fully type-safe and trim-friendly.
The examples in this repository cover several common mapping scenarios:
- Basic Mapping: Simple object-to-object mapping where property names and types match. See
SampleMapperTests.cs. - Properties with Different Names: Using the
[MapProperty]attribute to map properties when names don't match. SeePropertiesWithDifferentNamesTests.cs. - Enum Mapping: Customizing enum mapping using
[MapEnum]and[MapEnumValue]to handle different naming strategies or specific value mappings. SeeEnumMapperTests.cs. - Custom Mapping Logic: Integrating manual mapping logic or sub-mappers for complex transformations. See
MapperWithSubMapperTests.cs.
To run the examples and verify the mappings, use the .NET CLI:
dotnet testriok-mapperly-examples/: Contains the test project with all mapper definitions and examples.SampleMapperTests.cs: Basic mapping example.EnumMapperTests.cs: Enum mapping with strategies and value overrides.PropertiesWithDifferentNamesTests.cs: Mapping between different property names.MapperWithSubMapperTests.cs: Custom mapping methods.