Minicon.CodeMapper 0.1.1

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

Minicon.CodeMapper

Schlanker Objekt-zu-Objekt-Mapper für .NET auf Basis eines Source Generators – als Ablösung für AutoMapper. Die vertraute Profile / CreateMap-DSL bleibt erhalten, die Mappings werden jedoch zur Compile-Zeit als statischer, reflection-freier Code erzeugt.

  • Schnell – keine Reflection im heißen Pfad, nur direkte Zuweisungen und Delegate-Lookups
  • 🧩 Vertraute APIProfile, CreateMap<,>(), ForMember, MapFrom, Ignore, ReverseMap
  • 🔍 Compile-Zeit-Diagnostics – nicht zuordenbare Ziel-Member werden direkt im Build gemeldet
  • 🪶 Trimming-/AOT-freundlich – der generierte Mapping-Code ist vollständig statisch
  • 🆓 MIT-Lizenz – keine kommerzielle Lizenzpflicht

Status: v0.1 – die Kern-Features stehen und sind getestet. Siehe Roadmap.


Installation

Projektreferenz (während der Entwicklung):

<ProjectReference Include="path/to/src/Minicon.CodeMapper/Minicon.CodeMapper.csproj" />

Der zugehörige Source Generator ist im Paket enthalten und wird automatisch aktiv.

Schnellstart

1. Profile definieren – exakt wie gewohnt:

using Minicon.CodeMapper;

public class PersonProfile : Profile
{
    public PersonProfile()
    {
        CreateMap<Address, AddressDto>().ReverseMap();
        CreateMap<Order, OrderDto>();
        CreateMap<Person, PersonDto>()
            .ForMember(d => d.FullName, o => o.MapFrom(s => s.FirstName + " " + s.LastName))
            .ForMember(d => d.Secret,   o => o.Ignore());
    }
}

2. Registrieren (Microsoft.Extensions.DependencyInjection):

services.AddCodeMapper(typeof(PersonProfile).Assembly);

3. Mappen:

public class PersonService(IMapper mapper)
{
    public PersonDto ToDto(Person p) => mapper.Map<PersonDto>(p);
    public List<PersonDto> ToDtos(IEnumerable<Person> people) => mapper.Map<List<PersonDto>>(people);
}

Ohne DI geht es auch statisch über Mapper.Instance:

var dto = Mapper.Instance.Map<PersonDto>(person);

Unterstützte Features (v0.1)

Feature Status Hinweis
CreateMap<TSource, TDestination>() Property-/Feld-Zuordnung nach Name
ForMember(..., o => o.MapFrom(s => expr)) beliebiger Quell-Ausdruck
ForMember(..., o => o.Ignore())
ReverseMap() erzeugt Auto-Mapping in Gegenrichtung
Verschachtelte Objekte nutzt registriertes Sub-Mapping
Collections (List<T>, T[], IEnumerable<T>, …) Element-Mapping
Nullable<T>T via GetValueOrDefault()
Implizite Konvertierungen z. B. intlong
ConvertUsing(...) vollständig benutzerdefinierte Konvertierung
BeforeMap / AfterMap 🚧 DSL vorhanden, noch ohne Codegen
ConstructUsing 🚧 geplant
ValueResolver / Condition / NullSubstitute 🚧 geplant

Nicht zugeordnete Ziel-Member erzeugen die Compile-Zeit-Diagnose MINI001 (Severity: Info).

Migration von AutoMapper

In den meisten Fällen genügt das Ersetzen des Namespaces und der DI-Methode:

AutoMapper Minicon.CodeMapper
using AutoMapper; using Minicon.CodeMapper;
class X : Profile class X : Profile (unverändert)
CreateMap<A, B>()... unverändert
IMapper / mapper.Map<T>(x) unverändert
services.AddAutoMapper(asm) services.AddCodeMapper(asm)

Wie es funktioniert

  1. Der Source Generator findet alle Profile-Subklassen und liest deren CreateMap/ForMember-Deklarationen aus dem Syntaxbaum.
  2. Pro Typ-Paar wird eine statische Methode erzeugt (new TDest { ... } mit direkten Zuweisungen).
  3. Alle Methoden werden per [ModuleInitializer] in der MapperRegistry registriert – ganz ohne Assembly-Scan zur Laufzeit.
  4. IMapper.Map<T>() ist nur noch ein Dictionary-Lookup auf den passenden Delegate.

Auszug aus generiertem Code:

internal static PersonDto Map_3(Person source, IMapper mapper)
{
    if (source is null) return default!;
    return new PersonDto
    {
        Id        = source.Id,
        FullName  = ((Func<Person, string>)(s => s.FirstName + " " + s.LastName))(source),
        LuckyNumber = source.LuckyNumber.GetValueOrDefault(),
        HomeAddress = mapper.Map<AddressDto>(source.HomeAddress),
        Orders      = mapper.Map<List<OrderDto>>(source.Orders),
        // Secret wird ignoriert
    };
}

Trimming & AOT

Der generierte Mapping-Code ist vollständig statisch typisiert und reflection-frei. Einzige Ausnahme ist ein Komfort-Fallback in Mapper für Top-Level-Collection-Aufrufe wie Map<List<T>>(...), der minimale Reflection nutzt (sauber annotiert). Für NativeAOT empfiehlt es sich, registrierte Element-Mappings direkt zu verwenden; die automatische Generierung dedizierter Collection-Maps ist auf der Roadmap.

Roadmap

  • Inline-Codegen für Collections (vollständige AOT-Reinheit ohne Reflection-Fallback)
  • BeforeMap / AfterMap / ConstructUsing im Codegen
  • Condition, NullSubstitute, ValueResolver
  • Flattening (Order.Customer.NameOrderDto.CustomerName)
  • NuGet-Veröffentlichung
  • Drop-in-Kompatibilitätspaket (Namespace-Alias AutoMapper)

Build & Test

dotnet build
dotnet test

Lizenz

MIT © Michael Nikolaus

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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 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.

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
0.1.1 121 6/25/2026
0.1.0 107 6/25/2026