CleanArch.DevKit.Mapping 0.1.0-preview.1

This is a prerelease version of CleanArch.DevKit.Mapping.
There is a newer version of this package available.
See the version list below for details.
dotnet add package CleanArch.DevKit.Mapping --version 0.1.0-preview.1
                    
NuGet\Install-Package CleanArch.DevKit.Mapping -Version 0.1.0-preview.1
                    
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="CleanArch.DevKit.Mapping" Version="0.1.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CleanArch.DevKit.Mapping" Version="0.1.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="CleanArch.DevKit.Mapping" />
                    
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 CleanArch.DevKit.Mapping --version 0.1.0-preview.1
                    
#r "nuget: CleanArch.DevKit.Mapping, 0.1.0-preview.1"
                    
#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 CleanArch.DevKit.Mapping@0.1.0-preview.1
                    
#: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=CleanArch.DevKit.Mapping&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CleanArch.DevKit.Mapping&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Tool

CleanArch.DevKit.Mapping

Source-generated object mapping driven by the [Mapper<TFrom, TTo>] generic attribute. Standalone — no mediator dependency. The Roslyn generator ships inside the package as an analyzer asset.

Part of the CleanArch.DevKit toolkit.

Install

dotnet add package CleanArch.DevKit.Mapping

Quick start

public sealed class User
{
    public Guid Id { get; init; }
    public string Email { get; init; } = default!;
    public string Name { get; init; } = default!;
}

public sealed record UserDto(Guid Id, string Email, string Name);

[Mapper<User, UserDto>]
public partial class UserMapper
{
    public partial UserDto Map(User source);
}

// Registration
services.AddMappers();

// Use
var dto = provider.GetRequiredService<UserMapper>().Map(user);
// or via the aggregator
var dto2 = provider.GetRequiredService<IMapper>().Map<UserDto>(user);

How it works

  • The generator implements the partial Map method.
  • Property matching is by name, case-insensitive (so records' camelCase ctor parameters match PascalCase source properties).
  • Records use positional constructor: new UserDto(p1, p2, …).
  • Classes use the parameterless constructor + object initializer.

Per-property override

When the convention isn't enough, declare a private static helper named Map{Destination} taking the source. The generator picks it up:

[Mapper<User, UserDto>]
public partial class UserMapper
{
    public partial UserDto Map(User source);

    private static string MapName(User source)
        => $"{source.FirstName} {source.LastName}";
}

DI

AddMappers() is source-generated. It registers each concrete mapper as singleton (zero-boxing injection) and an IMapper aggregator backed by a Dictionary<(Type src, Type dst), Func<object, object>> built at construction. IMapper.Map<TDest>(object source) throws MappingNotFoundException on miss.

Diagnostics

Code Severity Meaning
MAP001 Error A destination property has no matching source property and no MapXxx override

License

MIT — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

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
1.1.1 89 5/17/2026
1.1.0 89 5/17/2026
1.0.0 86 5/15/2026
0.1.0-preview.1 47 5/14/2026