CHD.Mapping.Fody 10.0.0

dotnet add package CHD.Mapping.Fody --version 10.0.0
                    
NuGet\Install-Package CHD.Mapping.Fody -Version 10.0.0
                    
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="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CHD.Mapping.Fody" Version="10.0.0" />
                    
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 10.0.0
                    
#r "nuget: CHD.Mapping.Fody, 10.0.0"
                    
#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@10.0.0
                    
#: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=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CHD.Mapping.Fody&version=10.0.0
                    
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

There are no supported framework assets in this 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
10.0.0 94 8/16/2026
8.1.3 87 8/16/2026
8.1.2 147 2/19/2026
8.1.1 138 1/23/2026
8.1.0 143 1/20/2026
8.0.9 133 1/20/2026
8.0.8 142 1/17/2026
8.0.7 154 1/17/2026