Chd.Mapping.Abstractions
8.0.5
dotnet add package Chd.Mapping.Abstractions --version 8.0.5
NuGet\Install-Package Chd.Mapping.Abstractions -Version 8.0.5
<PackageReference Include="Chd.Mapping.Abstractions" Version="8.0.5" />
<PackageVersion Include="Chd.Mapping.Abstractions" Version="8.0.5" />
<PackageReference Include="Chd.Mapping.Abstractions" />
paket add Chd.Mapping.Abstractions --version 8.0.5
#r "nuget: Chd.Mapping.Abstractions, 8.0.5"
#:package Chd.Mapping.Abstractions@8.0.5
#addin nuget:?package=Chd.Mapping.Abstractions&version=8.0.5
#tool nuget:?package=Chd.Mapping.Abstractions&version=8.0.5
Library.Mapping.Abstractions
Chd (Cleverly Handle Difficulty) library helps you cleverly handle difficulty, write code quickly, and keep your application stable.
This library contains abstractions for below packages
- https://www.nuget.org/packages/Chd.Mapping.Fody
- https://www.nuget.org/packages/Chd.Mapping.Roslyn.Advanced
- https://www.nuget.org/packages/Chd.Mapping.Roslyn
What is Library.Mapping?
Library.Mapping is a high-performance, compile-time object mapper for .NET applications. It generates mapping code during your build, eliminating both the runtime reflection overhead and common type-safety pitfalls of traditional mappers.
Why Compile-time Mapping?
- Performance: Mapping logic is generated and inlined during compilation. No reflection or emitted code at runtime.
- Type Safety: Catches potential mapping errors during build instead of at runtime.
- IDE Support: Full access to code analysis, refactoring tools, and intellisense.
- Debuggability: Trace actual mapping logic in code, set breakpoints, and step through mappings.
Compile-time vs Runtime Mapping
| Feature | Compile-time Mapping (Library.Mapping) | Runtime Mapping (AutoMapper/Mapster) |
|---|---|---|
| Performance | Fastest (Ahead-of-Time, no reflection) | Slower (Reflection/Emission) |
| Type Safety | Compile-time error detection | Runtime errors possible |
| Refactoring | IDE-friendly, easy renaming | Mapping config requires manual update |
| Debugging | Set breakpoints, step over code | Hard to debug, dynamic code |
| Deployment | No mapper runtime dependency | Needs mapping lib at runtime |
.NET Benchmark Results
| Scenario | AutoMapper (ms) | Mapster (ms) | Library.Mapping (ms) |
|---|---|---|---|
| 1M DTO→Entity Map (Release x64) | 980 | 410 | 180 |
| 100K Entity→DTO Map with Nesting | 180 | 74 | 34 |
| Flat object, assign all properties | 22 | 10 | 4 |
Benchmark code in /benchmarks/Mapping.Benchmark.
Installation
1. Install NuGet package:
Install-Package Library.Mapping.Fody
2. Add FodyWeavers.xml: In the root of your project, add or update:
<Weavers>
<Library.Mapping/>
</Weavers>
3. Build project:
- The weaver will generate mapper implementations during build.
Code Samples: Modern DTO-Entity Mapping
Define DTO and Entity:
using Library.Mapping;
public class UserDto {
[MapTo(typeof(UserEntity))]
public int Id { get; set; }
public string Name { get; set; }
}
public class UserEntity {
[MapFrom(typeof(UserDto))]
public int Id { get; set; }
public string Name { get; set; }
}
Operator Injection
Both source and target can define implicit/explicit conversion operators, or use provided extension methods:
var entity = userDto.MapTo<UserEntity>(); // Extension method
UserEntity entity2 = userDto; // Operator overload (if injected by mapping)
Usage
After building, mapping methods and conversions are generated. Example usage:
var dto = new UserDto { Id = 1, Name = "Alice" };
UserEntity entity = dto; // Implicitly mapped
var dto2 = entity.MapTo<UserDto>(); // Back to DTO
- All mappings are validated at compile-time.
- Customization via mapping attributes available (see wiki).
Build & Integration Tips
- Confirm
Fodypackages are installed and correctFodyWeavers.xmlexists. - Clean & rebuild if generated code isn't appearing.
- Compatible with .NET Core, .NET Framework, and SDK-style projects.
- No runtime dependency except standard BCL.
Test & Benchmark
- See
/benchmarks/Mapping.Benchmarkproject for reproducible performance data. - CI runs mapping integration tests on PRs.
Test Repository For Usage
This repository contains examples of how to use the Library.Mapping package in different scenarios, including DTO-Entity mapping, operator injection, and performance benchmarks.
Authors
Acknowledgements
- Inspired by Fody community and .NET performance advocates.
- Thanks to users reporting issues and requesting features.
| 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 (3)
Showing the top 3 NuGet packages that depend on Chd.Mapping.Abstractions:
| Package | Downloads |
|---|---|
|
Chd.Mapping.Roslyn
Chd (Cleverly Handle Difficulty) packages are easy to use. Automatically maps DTO and Entity classes without any configuration, generating implicit mapping operators at compile time using [MapTo] and optional property-level mapping via [MapProperty]. |
|
|
Chd.Mapping.Roslyn.Advanced
Chd (Cleverly Handle Difficulty) packages are easy to use. Automatically maps DTO and Entity classes without any configuration. Now supports advanced mapping scenarios, custom value converters, nested object mapping, and improved performance for large projects. |
|
|
Chd.Mapping.Fody
Chd (Cleverly Handle Difficulty) packages are easy to use. High-performance, compile-time object mapping for .NET. Chd.Mapping.Fody generates type-safe, zero-reflection mapping code between DTOs and entities using simple attributes. All mapping logic is injected at build time for maximum speed and no runtime dependency. Supports property renaming, nested mapping, and implicit/explicit |
GitHub repositories
This package is not used by any popular GitHub repositories.