Chd.Mapping.Fody 8.1.2

dotnet add package Chd.Mapping.Fody --version 8.1.2
                    
NuGet\Install-Package Chd.Mapping.Fody -Version 8.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Chd.Mapping.Fody" Version="8.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Chd.Mapping.Fody" Version="8.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Chd.Mapping.Fody" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Chd.Mapping.Fody --version 8.1.2
                    
#r "nuget: Chd.Mapping.Fody, 8.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Chd.Mapping.Fody@8.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Chd.Mapping.Fody&version=8.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Chd.Mapping.Fody&version=8.1.2
                    
Install as a Cake Tool

Library.Mapping.Fody – High-Performance Compile-time DTO ↔ Entity Mapper for .NET

Chd (Cleverly Handle Difficulty) library helps you cleverly handle difficulty, write code quickly, and keep your application stable.

NuGet License

🚩 Important Note:
When using Library.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 normal: 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.
If the weaver fails or is misconfigured, runtime errors may occur.
Always ensure your project is built with Fody and check the build output for Fody logs.


📝 Table of Contents


What is Library.Mapping.Fody?

Library.Mapping.Fody is a high-performance, compile-time object mapping library for .NET.
It uses IL weaving to generate mapping code during build, eliminating runtime reflection and manual boilerplate mapping logic.

Key Advantages

  • Performance: Mapping logic is injected at compile-time. No runtime reflection.
  • Type Safety: Mapping matches property names and warns for mismatches at build.
  • Simplicity: Just add attributes and build. No config files, no DI, no surprises.
  • Debuggability: The generated mapping code is real .NET MSIL – step through and inspect at runtime.
  • No runtime dependency: Only .NET and Fody required at build.

Features

  • Attribute-based mapping: [MapTo] (DTO), [MapProperty] (for property name remapping)
  • Automatic mapping of matching properties, including collections (with identical element types)
  • Property remapping via [MapProperty("TargetPropertyName")]
  • Supports implicit operator for DTO → Entity
  • Adds MapTo() instance method for DTO → Entity mapping
  • No runtime mapping configuration, pure compile-time mapping
  • Works in .NET Core, .NET Framework, SDK-style projects

Installation

  1. Install NuGet package:

    Install-Package Library.Mapping.Fody
    
  2. Add FodyWeavers.xml in your project root:

    <Weavers>
      <Library.Mapping/>
    </Weavers>
    
  3. Build your project:
    Fody will inject mapping methods and operators into your compiled output.


Usage

Basic Mapping

using System;
using Library.Mapping;

public class UserDto
{
    [MapTo(typeof(UserEntity))]
    public int Id { get; set; }
    public string Name { get; set; }
}

public class UserEntity
{
    public int Id { get; set; }
    public string Name { get; set; }
}

class Program
{
    static void Main()
    {
        var dto = new UserDto { Id = 1, Name = "Alice" };

        // Supported mapping usages:
        UserEntity entity1 = dto;         // implicit operator (Fody generated)
        UserEntity entity2 = dto.MapTo(); // instance MapTo method (Fody generated)

        Console.WriteLine($"Id: {entity1.Id}");
        Console.WriteLine($"Name: {entity1.Name}");
    }
}

Console Output:

Id: 1
Name: Alice

Property Remapping

using System;
using Library.Mapping;

public class UserDto
{
    [MapTo(typeof(UserEntity))]
    [MapProperty("FullName")]
    public string Name { get; set; }
    public int Id { get; set; }
}

public class UserEntity
{
    public int Id { get; set; }
    public string FullName { get; set; }
}

class Program
{
    static void Main()
    {
        var dto = new UserDto { Id = 42, Name = "Mehmet Yoldaş" };
        UserEntity entity = dto.MapTo();

        Console.WriteLine($"Id: {entity.Id}");
        Console.WriteLine($"FullName: {entity.FullName}");
    }
}

Console Output:

Id: 42
FullName: Mehmet Yoldaş

Collection Mapping

using System;
using System.Collections.Generic;
using Library.Mapping;

public class ProductDto
{
    [MapTo(typeof(ProductEntity))]
    public string Code { get; set; }
    public int Quantity { get; set; }
}

public class ProductEntity
{
    public string Code { get; set; }
    public int Quantity { get; set; }
}

public class OrderDto
{
    [MapTo(typeof(OrderEntity))]
    public int OrderId { get; set; }
    public List<ProductDto> Products { get; set; }
}

public class OrderEntity
{
    public int OrderId { get; set; }
    public List<ProductEntity> Products { get; set; }
}

class Program
{
    static void Main()
    {
        var dto = new OrderDto
        {
            OrderId = 3,
            Products = new List<ProductDto>
            {
                new ProductDto { Code = "A123", Quantity = 2 },
                new ProductDto { Code = "B456", Quantity = 5 }
            }
        };

        OrderEntity entity = dto.MapTo();

        Console.WriteLine($"OrderId: {entity.OrderId}");
        foreach (var p in entity.Products)
            Console.WriteLine($"Product: {p.Code} - {p.Quantity}");
    }
}

Console Output:

OrderId: 3
Product: A123 - 2
Product: B456 - 5

Limitations & Notes

  • Mapping is only supported from DTO (with [MapTo]) to the target Entity type.
  • Reverse mapping (Entity → DTO) is not generated.
  • You cannot use entity.MapTo() or entity.MapTo<UserDto>().
  • IntelliSense and the C# compiler may not see injected members; test at runtime after building.
  • Only DTO→Entity direction is supported.
  • Custom mapping expressions are not supported; only property name remapping ([MapProperty]) is available.

Build & Integration Tips

  • Make sure Fody and Library.Mapping.Fody packages are installed.
  • Ensure FodyWeavers.xml exists in your project.
  • If mapping code doesn't appear, clean & rebuild.
  • Mapping code is injected only on classes with [MapTo(typeof(TargetType))].

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.

For issues, feature requests, or contributions, please visit mehmet-yoldas/library-core

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.1.2 86 2/19/2026
8.1.1 92 1/23/2026
8.1.0 100 1/20/2026
8.0.9 91 1/20/2026
8.0.8 103 1/17/2026
8.0.7 108 1/17/2026