CleanArch.DevKit.Mapping
0.1.0-preview.1
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
<PackageReference Include="CleanArch.DevKit.Mapping" Version="0.1.0-preview.1" />
<PackageVersion Include="CleanArch.DevKit.Mapping" Version="0.1.0-preview.1" />
<PackageReference Include="CleanArch.DevKit.Mapping" />
paket add CleanArch.DevKit.Mapping --version 0.1.0-preview.1
#r "nuget: CleanArch.DevKit.Mapping, 0.1.0-preview.1"
#:package CleanArch.DevKit.Mapping@0.1.0-preview.1
#addin nuget:?package=CleanArch.DevKit.Mapping&version=0.1.0-preview.1&prerelease
#tool nuget:?package=CleanArch.DevKit.Mapping&version=0.1.0-preview.1&prerelease
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
Mapmethod. - Property matching is by name, case-insensitive (so records'
camelCasector 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 | Versions 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. |
-
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 | 90 | 5/17/2026 |
| 1.1.0 | 90 | 5/17/2026 |
| 1.0.0 | 87 | 5/15/2026 |
| 0.1.0-preview.1 | 48 | 5/14/2026 |