Riok.Mapperly
                             
                            
                                2.1.0
                            
                        
                            
                                
                                
                                    Prefix Reserved
                                
                            
                    See the version list below for details.
dotnet add package Riok.Mapperly --version 2.1.0
NuGet\Install-Package Riok.Mapperly -Version 2.1.0
<PackageReference Include="Riok.Mapperly" Version="2.1.0" />
<PackageVersion Include="Riok.Mapperly" Version="2.1.0" />
<PackageReference Include="Riok.Mapperly" />
paket add Riok.Mapperly --version 2.1.0
#r "nuget: Riok.Mapperly, 2.1.0"
#:package Riok.Mapperly@2.1.0
#addin nuget:?package=Riok.Mapperly&version=2.1.0
#tool nuget:?package=Riok.Mapperly&version=2.1.0
Mapperly
Mapperly is a .NET source generator for generating object mappings. Inspired by MapStruct.
Because Mapperly creates the mapping code at build time, there is minimal overhead at runtime. Even better, the generated code is perfectly readable, allowing you to verify the generated mapping code easily.
Mapperly is the fastet .NET object mapper out there, surpassing even the naive manual mapping approach! The benchmark was generated with https://github.com/mjebrahimi/Benchmark.netCoreMappers.
| Method | Mean | Error | StdDev | Gen 0 | Allocated | 
|---|---|---|---|---|---|
| AgileMapper | 1,523.8 ns | 3.90 ns | 3.25 ns | 1.5106 | 3,160 B | 
| TinyMapper | 4,094.3 ns | 3.90 ns | 3.05 ns | 1.0300 | 2,160 B | 
| ExpressMapper | 2,595.8 ns | 5.49 ns | 5.14 ns | 2.3422 | 4,904 B | 
| AutoMapper | 1,203.9 ns | 2.30 ns | 2.15 ns | 0.9098 | 1,904 B | 
| ManualMapping | 529.6 ns | 0.52 ns | 0.44 ns | 0.5541 | 1,160 B | 
| Mapster | 562.1 ns | 1.14 ns | 0.89 ns | 0.9098 | 1,904 B | 
| Mapperly | 338.5 ns | 0.95 ns | 0.84 ns | 0.4396 | 920 B | 
Quickstart
Installation
Add the NuGet Package to your project:
dotnet add package Riok.Mapperly
Create your first mapper
Create a mapper declaration as a partial class
and apply the Riok.Mapperly.Abstractions.MapperAttribute attribute.
Mapperly generates mapping method implementations for the defined mapping methods in the mapper.
// Mapper declaration
[Mapper]
public partial class DtoMapper
{
    public partial CarDto CarToCarDto(Car car);
}
// Mapper usage
var mapper = new DtoMapper();
var car = new Car { NumberOfSeats = 10, ... };
var dto = mapper.CarToCarDto(car);
dto.NumberOfSeats.Should().Be(10);
Configuration
The attributes defined in Riok.Mapperly.Abstractions can be used to customize different aspects of the generated mapper.
Mapper
The MapperAttribute provides options to customize the generated mapper class.
The default enum mapping and null handling strategy are adjustable.
Copy behaviour
By default, Mapperly does not create deep copies of objects to improve performance.
If an object can be directly assigned to the target, it will do so
(eg. if the source and target type are both Car[], the array and its entries will not be cloned).
To create deep copies, set the UseDeepCloning property on the MapperAttribute to true.
Properties
On each mapping method declaration, property mappings can be customized.
If a property on the target has a different name than on the source, the MapPropertyAttribute can be applied.
If a property should be ignored, the MapperIgnoreAttribute can be used.
Flattening and unflattening
It is pretty common to flatten objects during mapping, eg. Car.Make.Id => CarDto.MakeId.
Mapperly tries to figure out flattenings automatically by making use of the pascal case C# notation.
If Mapperly can't resolve the target or source property correctly, it is possible to manually configure it by applying the MapPropertyAttribute
by either using the source and target property path names as arrays or using a dot separated property access path string
[MapProperty(Source = new[] { nameof(Car), nameof(Car.Make), nameof(Car.Make.Id) }, Target = new[] { nameof(CarDto), nameof(CarDto.MakeId) })]
// Or alternatively
[MapProperty(Source = "Car.Make.Id", Target = "CarDto.MakeId")]
Note: Unflattening is not yet automatically configured by Mapperly and needs to be configured manually via MapPropertyAttribute.
Enum
The enum mapping can be customized by setting the strategy to use.
Apply the MapEnumAttribute and pass the strategy to be used for this enum.
It is also possible to set the strategy for the entire mapper via the MapperAttribute.
Available strategies:
| Name | Description | 
|---|---|
| ByValue | Matches enum entries by their values | 
| ByName | Matches enum entries by their exact names | 
The IgnoreCase property allows to opt in for case insensitive mappings.
User implemented mapping methods
If Mapperly cannot generate a mapping, one can implement it manually simply by providing a method body in the mapper declaration:
[Mapper]
public partial class DtoMapper
{
    public partial CarDto CarToCarDto(Car car);
    private DateOnly DateTimeToDateOnly(DateTime dt) => DateOnly.FromDateTime(dt);
}
Whenever Mapperly needs a mapping from DateTime to DateOnly inside the DtoMapper implementation, it will use the provided implementation.
Before / after map
To run custom code before or after a mapping, the generated map method can be wrapped in a custom method:
[Mapper]
public partial class DtoMapper
{
    public CarDto MapCarToCarDto(Car car)
    {
        // custom before map code...
        var dto = CarToCarDto(car);
        // custom after map code...
        return dto;
    }
    private partial CarDto CarToCarDto(Car car);
}
Void mapping methods
If an existing object instance should be used as target, you can define the mapping method as void with the target as second parameter:
// Mapper declaration
[Mapper]
public partial class DtoMapper
{
    public partial void CarToCarDto(Car car, CarDto dto);
}
// Mapper usage
var mapper = new DtoMapper();
var car = new Car { NumberOfSeats = 10, ... };
var dto = new CarDto();
mapper.CarToCarDto(car, dto);
dto.NumberOfSeats.Should().Be(10);
| Product | Versions Compatible and additional computed target framework versions. | 
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. | 
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. | 
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. | 
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. | 
| MonoAndroid | monoandroid was computed. | 
| MonoMac | monomac was computed. | 
| MonoTouch | monotouch was computed. | 
| Tizen | tizen40 was computed. tizen60 was computed. | 
| Xamarin.iOS | xamarinios was computed. | 
| Xamarin.Mac | xamarinmac was computed. | 
| Xamarin.TVOS | xamarintvos was computed. | 
| Xamarin.WatchOS | xamarinwatchos was computed. | 
- 
                                                    .NETStandard 2.0- No dependencies.
 
NuGet packages (30)
Showing the top 5 NuGet packages that depend on Riok.Mapperly:
| Package | Downloads | 
|---|---|
| AssemblyAI The AssemblyAI C# .NET SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, audio intelligence models, as well as the latest LeMUR models. | |
| Indice.Hive.Core Package Description | |
| Rocket.Surgery.LaunchPad.Mapping Package Description | |
| Fanzoo.Kernel An opinionated framework for building scalable web applications. | |
| TossPlatform.Common TossPlatform Common for SDK | 
GitHub repositories (23)
Showing the top 20 popular GitHub repositories that depend on Riok.Mapperly:
| Repository | Stars | 
|---|---|
| abpframework/abp 
                                                            Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
                                                         | |
| martinothamar/Mediator 
                                                            A high performance implementation of Mediator pattern in .NET using source generators.
                                                         | |
| lookup-foundation/RevitLookup 
                                                            Interactive Revit RFA and RVT project database exploration tool to view and navigate BIM element parameters, properties and relationships.
                                                         | |
| bitfoundation/bitplatform 
                                                            Build all of your apps using what you already know and love ❤️
                                                         | |
| velopack/velopack 
                                                            Installer and automatic update framework for cross-platform desktop applications
                                                         | |
| mehdihadeli/food-delivery-microservices 
                                                            🍔 A practical and cloud-native food delivery microservices, built with .Net Aspire, .Net 9, MassTransit, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
                                                         | |
| Tim-Maes/Facet 
                                                            Generate Facets, DTOs, projections, and mappers from complex domain models.
                                                         | |
| ThingsGateway/ThingsGateway 
                                                            ThingsGateway is a cross-platform, high-performance gateway for edge data acquisition and IoT connectivity. Developed with .NET 8, it offers a suite of powerful tools, including advanced PLC communication libraries and debugging software.
                                                         | |
| yanpitangui/dotnet-api-boilerplate 
                                                            A Dotnet 9.0 WebApi template project. MediatR, Swagger, Mapper, Serilog and more implemented. 
                                                         | |
| nkdAgility/azure-devops-migration-tools 
                                                            Azure DevOps Migration Tools allow you to migrate Teams, Backlogs, Work Items, Tasks, Test Cases, and Plans & Suits from one Project to another in Azure DevOps / TFS both within the same Organisation, and between Organisations.
                                                         | |
| josephnhtam/live-streaming-server-net 
                                                            A .NET implementation of RTMP live streaming server, supporting HTTP-FLV, WebSocket-FLV, HLS, Kubernetes, cloud storage services integration and more.
                                                         | |
| mehdihadeli/vertical-slice-api-template 
                                                            🍰 An asp.net core template based on .Net 9, Vertical Slice Architecture, CQRS, Minimal APIs, OpenTelemetry, API Versioning and OpenAPI.
                                                         | |
| svrooij/WinTuner 
                                                            Package any app from Winget to Intune - WinTuner
                                                         | |
| higty/higlabo 
                                                            HigLabo library provide 1.AI client library(OpenAI, Anthoripic, Groq) 2.Object Mapper(fastest in the world) 3.DbSharp(DAL generator) 4.Other.(Mail, Ftp, Utility...etc)
                                                         | |
| Azure/iotedge-lorawan-starterkit 
                                                            Sample implementation of LoRaWAN components to connect LoRaWAN antenna gateway running IoT Edge directly with Azure IoT.
                                                         | |
| westonwalker/BlazorMinimalAPI | |
| asesidaa/EXVS2-POC | |
| harrison314/BouncyHsm 
                                                            Bouncy Hsm is a software simulator of HSM and smartcard simulator with HTML UI, REST API and PKCS#11 interface.
                                                         | |
| SapiensAnatis/Dawnshard 
                                                            Server emulator for Dragalia Lost
                                                         | |
| MDModsDev/MuseDashModTools 
                                                            UI app made by Avalonia framework for Muse Dash Mods
                                                         | 
| Version | Downloads | Last Updated | 
|---|---|---|
| 4.3.0 | 33,663 | 10/21/2025 | 
| 4.3.0-next.6 | 761 | 10/15/2025 | 
| 4.3.0-next.5 | 1,760 | 10/7/2025 | 
| 4.3.0-next.4 | 2,189 | 9/18/2025 | 
| 4.3.0-next.3 | 6,831 | 7/29/2025 | 
| 4.3.0-next.2 | 8,998 | 6/16/2025 | 
| 4.3.0-next.1 | 472 | 6/13/2025 | 
| 4.3.0-next.0 | 1,621 | 5/27/2025 | 
| 4.2.1 | 1,948,990 | 4/23/2025 | 
| 4.2.1-next.2 | 227 | 4/21/2025 | 
| 4.2.1-next.1 | 275 | 4/20/2025 | 
| 4.2.1-next.0 | 1,098 | 4/8/2025 | 
| 4.2.0 | 444,082 | 3/26/2025 | 
| 4.2.0-next.2 | 1,595 | 3/18/2025 | 
| 4.2.0-next.1 | 3,608 | 2/17/2025 | 
| 4.2.0-next.0 | 64,058 | 1/20/2025 | 
| 4.1.1 | 2,783,376 | 11/20/2024 | 
| 4.1.1-next.0 | 25,503 | 11/5/2024 | 
| 4.1.0 | 682,458 | 10/31/2024 | 
| 4.1.0-next.3 | 235 | 10/29/2024 | 
| 4.1.0-next.2 | 1,025 | 10/25/2024 | 
| 4.1.0-next.1 | 1,193 | 10/14/2024 | 
| 4.1.0-next.0 | 8,198 | 10/11/2024 | 
| 4.0.0 | 313,603 | 10/11/2024 | 
| 4.0.0-next.4 | 2,987 | 9/29/2024 | 
| 4.0.0-next.3 | 29,593 | 8/13/2024 | 
| 4.0.0-next.2 | 546 | 8/6/2024 | 
| 4.0.0-next.1 | 14,165 | 6/30/2024 | 
| 3.6.0 | 1,897,261 | 6/18/2024 | 
| 3.6.0-next.2 | 4,062 | 6/3/2024 | 
| 3.6.0-next.1 | 7,992 | 5/3/2024 | 
| 3.5.1 | 629,900 | 4/23/2024 | 
| 3.5.1-next.2 | 4,162 | 4/15/2024 | 
| 3.5.1-next.1 | 296 | 4/9/2024 | 
| 3.5.0 | 464,924 | 4/5/2024 | 
| 3.5.0-next.4 | 1,540 | 3/27/2024 | 
| 3.5.0-next.3 | 9,953 | 3/18/2024 | 
| 3.5.0-next.2 | 40,719 | 3/11/2024 | 
| 3.5.0-next.1 | 975 | 3/9/2024 | 
| 3.4.0 | 504,711 | 2/23/2024 | 
| 3.4.0-next.5 | 1,989 | 2/20/2024 | 
| 3.4.0-next.4 | 943 | 2/16/2024 | 
| 3.4.0-next.3 | 5,766 | 2/5/2024 | 
| 3.4.0-next.2 | 25,161 | 1/10/2024 | 
| 3.4.0-next.1 | 392 | 1/6/2024 | 
| 3.3.1-next.1 | 3,019 | 12/18/2023 | 
| 3.3.0 | 713,545 | 12/12/2023 | 
| 3.3.0-next.6 | 1,083 | 12/6/2023 | 
| 3.3.0-next.5 | 1,441 | 11/28/2023 | 
| 3.3.0-next.4 | 2,823 | 11/22/2023 | 
| 3.3.0-next.3 | 9,488 | 11/19/2023 | 
| 3.3.0-next.2 | 4,131 | 10/26/2023 | 
| 3.3.0-next.1 | 4,071 | 10/11/2023 | 
| 3.2.0 | 809,569 | 9/18/2023 | 
| 3.2.0-next.4 | 1,474 | 9/12/2023 | 
| 3.2.0-next.3 | 561 | 9/11/2023 | 
| 3.2.0-next.2 | 415 | 9/5/2023 | 
| 3.2.0-next.1 | 569 | 8/29/2023 | 
| 3.1.0 | 168,613 | 8/18/2023 | 
| 3.1.0-next.2 | 193 | 8/18/2023 | 
| 3.1.0-next.1 | 4,809 | 8/8/2023 | 
| 3.0.0 | 47,071 | 8/7/2023 | 
| 3.0.0-next.1 | 510 | 8/2/2023 | 
| 2.9.0-next.4 | 7,945 | 7/26/2023 | 
| 2.9.0-next.3 | 1,003 | 7/16/2023 | 
| 2.9.0-next.2 | 5,173 | 6/13/2023 | 
| 2.9.0-next.1 | 5,714 | 5/11/2023 | 
| 2.8.0 | 698,879 | 4/27/2023 | 
| 2.8.0-next.2 | 620 | 4/20/2023 | 
| 2.8.0-next.1 | 20,065 | 3/23/2023 | 
| 2.7.1-next.1 | 767 | 3/17/2023 | 
| 2.7.0 | 197,587 | 3/13/2023 | 
| 2.7.0-next.2 | 951 | 1/26/2023 | 
| 2.7.0-next.1 | 721 | 1/23/2023 | 
| 2.6.0 | 116,484 | 1/12/2023 | 
| 2.6.0-next.4 | 223 | 1/11/2023 | 
| 2.6.0-next.3 | 270 | 1/9/2023 | 
| 2.6.0-next.2 | 415 | 12/14/2022 | 
| 2.6.0-next.1 | 694 | 12/12/2022 | 
| 2.5.0 | 97,425 | 10/12/2022 | 
| 2.5.0-next.2 | 446 | 9/28/2022 | 
| 2.5.0-next.1 | 358 | 9/19/2022 | 
| 2.4.1-next.1 | 323 | 9/16/2022 | 
| 2.4.0 | 22,277 | 9/8/2022 | 
| 2.3.3 | 3,367 | 8/10/2022 | 
| 2.3.2 | 1,148 | 8/9/2022 | 
| 2.3.1 | 61,922 | 5/31/2022 | 
| 2.3.0 | 2,658 | 5/16/2022 | 
| 2.2.1 | 3,784 | 4/6/2022 | 
| 2.2.0 | 1,510 | 3/15/2022 | 
| 2.1.0 | 1,328 | 2/28/2022 | 
| 2.0.0 | 1,536 | 2/21/2022 | 
# [2.1.0](https://github.com/riok/mapperly/compare/v2.0.0...v2.1.0) (2022-02-28)
### Bug Fixes
* handle nullable types in disabled nullability contexts inside enumerables correctly ([#31](https://github.com/riok/mapperly/issues/31)) ([6efb262](https://github.com/riok/mapperly/commit/6efb26263e9a80bb01793b09da733d31045457ac))
### Features
* improve enumerable performance ([#33](https://github.com/riok/mapperly/issues/33)) ([2488e7d](https://github.com/riok/mapperly/commit/2488e7dbf2d8fd590b7cfb07336a4fc6f1b3b0ea))
* support flattening ([#29](https://github.com/riok/mapperly/issues/29)) ([ca6f4aa](https://github.com/riok/mapperly/commit/ca6f4aa6d54cc6bd1ca2f014cab8ff97d1337350))