DotNetBrightener.Mapper 2026.0.2

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

DotNetBrightener.Mapper

Copyright © 2017 - 2026 Vampire Coder (formerly DotnetBrightener)

DotNetBrightener.Mapper is a compile-time DTO and projection generator for .NET.

Define a target type once with MappingTarget<TSource>, and the generator produces the mapping surface for you:

  • source constructor
  • parameterless constructor when enabled
  • Projection expression for LINQ and EF Core
  • ToSource() for reverse mapping when enabled
  • patch/update helpers through the mapping packages

The project is split into focused packages so you only install what you need.

Packages

Core generator

dotnet add package DotNetBrightener.Mapper

This package provides the source generator and analyzer support.

Attributes only

dotnet add package DotNetBrightener.Mapper.Attributes

Use this when you only need the runtime attributes and enums.

Mapping extensions

dotnet add package DotNetBrightener.Mapper.Mapping

This package adds:

  • ToTarget
  • ToSource
  • SelectTargets
  • SelectSources
  • SelectTarget
  • ApplyTarget
  • ApplyTargetWithChanges
  • custom mapping interfaces
  • expression mapping helpers

EF Core mapping extensions

dotnet add package DotNetBrightener.Mapper.Mapping.EFCore

This package adds EF Core-specific helpers such as:

  • ToTargetsAsync
  • FirstAsync
  • SingleAsync
  • UpdateFromTarget
  • UpdateFromTargetAsync
  • UpdateFromTargetWithChanges

Quick Example

using DotNetBrightener.Mapper;

public class User
{
    public int Id { get; set; }
    public string FirstName { get; set; } = string.Empty;
    public string LastName { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
    public string Password { get; set; } = string.Empty;
    public DateTime CreatedAt { get; set; }
}

[MappingTarget<User>("Password", "CreatedAt", GenerateToSource = true)]
public partial class UserDto;

The generated UserDto includes the mapped properties from User, a constructor from User, a Projection expression, and ToSource() because GenerateToSource = true.

Basic Mapping

With DotNetBrightener.Mapper.Mapping installed:

using DotNetBrightener.Mapper.Mapping;

var dto = user.ToTarget<UserDto>();
var dtoFast = user.ToTarget<User, UserDto>();

var entity = dto.ToSource<User>();
var entityFast = dto.ToSource<UserDto, User>();

var dtos = users.SelectTargets<UserDto>().ToList();
var projected = query.SelectTarget<UserDto>();

Nested Target Types

public class Address
{
    public string Street { get; set; } = string.Empty;
    public string City { get; set; } = string.Empty;
}

public class Company
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public Address HeadquartersAddress { get; set; } = null!;
}

[MappingTarget<Address>]
public partial record AddressDto;

[MappingTarget<Company>(NestedTargetTypes = [typeof(AddressDto)])]
public partial record CompanyDto;

Nested object and collection mappings are generated automatically when the nested target types are declared.

Custom Mapping

Static mapper:

using DotNetBrightener.Mapper.Mapping;
using DotNetBrightener.Mapper.Mapping.Configurations;

public class UserMapper : IMappingConfiguration<User, UserDto>
{
    public static void Map(User source, UserDto target)
    {
        target.FullName = $"{source.FirstName} {source.LastName}";
    }
}

[MappingTarget<User>(Configuration = typeof(UserMapper))]
public partial class UserDto
{
    public string FullName { get; set; } = string.Empty;
}

Instance mapper with DI:

using DotNetBrightener.Mapper.Mapping.Configurations;

public class UserMapperWithServices : IMappingConfigurationAsyncInstance<User, UserDto>
{
    private readonly IProfileService _profileService;

    public UserMapperWithServices(IProfileService profileService)
    {
        _profileService = profileService;
    }

    public async Task MapAsync(User source, UserDto target, CancellationToken cancellationToken = default)
    {
        target.ProfileUrl = await _profileService.GetProfileUrlAsync(source.Id, cancellationToken);
    }
}

Additional Attributes

The generator also supports:

  • MapFrom
  • MapWhen
  • Flatten
  • GenerateDtos
  • Wrapper

Additional generation options include:

  • Include
  • CopyAttributes
  • NullableProperties
  • ConvertEnumsTo
  • GenerateEquality
  • GenerateCopyConstructor
  • SourceSignature

Documentation

Project Packages

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DotNetBrightener.Mapper:

Package Downloads
DotNetBrightener.Mapper.Mapping

Advanced custom async mapper support, expression mapping, and extensions for DotNetBrightener.Mapper.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.0.3-preview-777 93 5/20/2026
2026.0.3-preview-773 111 4/24/2026
2026.0.3-preview-772 120 4/3/2026
2026.0.3-preview-770 116 4/2/2026
2026.0.3-preview-769 107 4/2/2026
2026.0.2 120 4/2/2026
2026.0.2-preview-v2026-0-1-755 107 3/27/2026
2026.0.2-preview-759 110 4/1/2026
2026.0.2-preview-758 112 3/29/2026
2026.0.2-preview-757 118 3/29/2026
2026.0.2-preview-756 111 3/27/2026
2026.0.2-preview-754 104 3/27/2026
2026.0.1 113 3/27/2026
2026.0.1-preview-752 114 3/26/2026
2026.0.1-preview-750 108 3/26/2026
2026.0.1-preview-749 113 3/25/2026
2026.0.1-preview-748 108 3/23/2026
2026.0.1-preview-746 91 3/22/2026
2026.0.1-preview-745 94 3/22/2026
2025.0.11-preview-776 218 5/20/2026
Loading failed