Chd.Mapping.Fody
8.0.8
See the version list below for details.
dotnet add package Chd.Mapping.Fody --version 8.0.8
NuGet\Install-Package Chd.Mapping.Fody -Version 8.0.8
<PackageReference Include="Chd.Mapping.Fody" Version="8.0.8" />
<PackageVersion Include="Chd.Mapping.Fody" Version="8.0.8" />
<PackageReference Include="Chd.Mapping.Fody" />
paket add Chd.Mapping.Fody --version 8.0.8
#r "nuget: Chd.Mapping.Fody, 8.0.8"
#:package Chd.Mapping.Fody@8.0.8
#addin nuget:?package=Chd.Mapping.Fody&version=8.0.8
#tool nuget:?package=Chd.Mapping.Fody&version=8.0.8
🚩 Important Note:
When using Chd.Mapping.Fody, your IDE (Visual Studio, Rider, etc.) may show red squiggly lines or error messages (such as "no implicit conversion" or "method not found") for generated mapping methods or operators.
This is expected: the mapping code is injected at the IL level after compilation, so it is not visible to IntelliSense or the C# compiler during editing.
You will not get a build error if Fody is configured correctly and the build completes successfully.
However, if the weaver is not run or misconfigured, you may encounter runtime errors.
Always ensure your project is built with Fody and check the build output for Fody logs.
Library.Mapping
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.
Authors
- Mehmet Yoldaş (mehmet-yoldas)
Acknowledgements
- Inspired by Fody community and .NET performance advocates.
- Thanks to users reporting issues and requesting features.
Note:
When using Chd.Mapping.Fody, you may see red squiggly lines or error messages in your IDE (such as "no implicit conversion" or "method not found") for generated mapping methods or operators.
This is expected: the mapping code is injected at the IL level after compilation, so it is not visible to IntelliSense or the C# compiler during editing.
You will not get a build error if Fody is configured correctly and the build completes successfully.
However, if the weaver is not run or misconfigured, you may encounter runtime errors.
Always ensure your project is built with Fody and check the build output for Fody logs.
| 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
- Chd.Mapping.Abstractions (>= 8.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.