DotNetBrightener.Mapper by Vampire Coder
NuGet / site data
Details
Info
Name: DotNetBrightener.Mapper
DotNetBrightener.Mapper is a compile-time DTO and projection generator. It generates source constructors, LINQ projection expressions, and optional reverse mapping from a MappingTarget source type.
Author: Vampire Coder
NuGet: https://www.nuget.org/packages/DotNetBrightener.Mapper/
You can find more details at https://github.com/dotnetbrightener/dotnet-brightener-framework
Source: https://github.com/dotnetbrightener/dotnet-brightener-framework
Author
Vampire Coder

Original Readme
DotNetBrightener.Mapper
DotNetBrightener.Mapper is a source generator for compile-time DTO and projection mapping in .NET.
The MappingTarget<TSource> attribute defines the target DTO from a source model. The generator creates mapped properties, a constructor that accepts the source type, and a Projection expression for LINQ and EF Core queries. Properties can be excluded from the generated target.
Package: https://www.nuget.org/packages/DotNetBrightener.Mapper/ Source: https://github.com/dotnetbrightener/dotnet-brightener-framework
About
Compile-time DTO and projection mapping
Generating source constructors and LINQ projection expressions
Excluding sensitive source properties from target DTOs
How to use
Example (source csproj, source files)
- CSharp Project
- Program.cs
- Person.cs
- PersonDto.cs
This is the CSharp Project that references DotNetBrightener.Mapper
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetBrightener.Mapper" Version="2026.0.2" />
</ItemGroup>
</Project>
This is the use of DotNetBrightener.Mapper in Program.cs
using MapperDemo;
var person = new Person
{
Id = 42,
FirstName = "Andrei",
LastName = "Ignat",
Password = "secret"
};
var dto = new PersonDto(person);
Console.WriteLine($"{dto.Id}: {dto.FullName}");
var projected = new[] \{ person }
.AsQueryable()
.Select(PersonDto.Projection)
.Single();
Console.WriteLine($"Projected: {projected.FullName}");
This is the use of DotNetBrightener.Mapper in Person.cs
namespace MapperDemo;
public class Person
{
public int Id \{ get; set; }
public string FirstName \{ get; set; \} = string.Empty;
public string LastName \{ get; set; \} = string.Empty;
public string Password \{ get; set; \} = string.Empty;
}
This is the use of DotNetBrightener.Mapper in PersonDto.cs
using DotNetBrightener.Mapper;
namespace MapperDemo;
[MappingTarget<Person>(nameof(Person.Password))]
public partial class PersonDto
{
public string FullName => $"{FirstName} {LastName}";
}
Generated Files
Those are taken from $(BaseIntermediateOutputPath)\GX
- MapperDemo.PersonDto.g.cs
// <auto-generated>
// This code was generated by the mapping target source generator v2026.0.2.0.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
using System;
using System.Linq;
using System.Linq.Expressions;
#nullable enable
namespace MapperDemo;
public partial class PersonDto
{
public int Id \{ get; set; }
public string FirstName \{ get; set; \} = string.Empty;
public string LastName \{ get; set; \} = string.Empty;
/// <summary>
/// Initializes a new instance of the <see cref="PersonDto"/> class with default values.
/// </summary>
/// <remarks>
/// This constructor is useful for unit testing, object initialization, and scenarios
/// where you need to create an empty instance and populate properties later.
/// </remarks>
public PersonDto()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="PersonDto"/> class from the specified <see cref="Person"/>.
/// </summary>
/// <param name="source">The source <see cref="Person"/> object to copy data from.</param>
public PersonDto(global::MapperDemo.Person source) : this(source, 0, new System.Collections.Generic.HashSet<object>(System.Collections.Generic.ReferenceEqualityComparer.Instance))
{
}
/// <summary>
/// Constructor with depth tracking to prevent stack overflow from circular references.
/// </summary>
/// <param name="source">The source object to copy data from.</param>
/// <param name="__depth">Current nesting depth for circular reference detection.</param>
/// <param name="__processed">Set of already processed objects to detect circular references.</param>
/// <remarks>
/// This constructor is public to support nested targets across different assemblies.
/// For typical usage, prefer the single-parameter constructor or FromSource factory method.
/// </remarks>
public PersonDto(global::MapperDemo.Person source, int __depth, System.Collections.Generic.HashSet<object>? __processed)
{
this.Id = source.Id;
this.FirstName = source.FirstName;
this.LastName = source.LastName;
}
/// <summary>
/// Creates a new instance of <see cref="PersonDto"/> from the specified <see cref="Person"/>.
/// </summary>
/// <param name="source">The source <see cref="Person"/> object to copy data from.</param>
/// <returns>A new <see cref="PersonDto"/> instance with all properties initialized from the source.</returns>
/// <remarks>
/// This static factory method provides optimal performance for runtime mapping by allowing
/// direct delegate creation instead of expression compilation.
/// </remarks>
public static PersonDto FromSource(global::MapperDemo.Person source)
{
return new PersonDto(source, 0, new System.Collections.Generic.HashSet<object>(System.Collections.Generic.ReferenceEqualityComparer.Instance));
}
/// <summary>
/// Gets the projection expression for converting <see cref="Person"/> to <see cref="PersonDto"/>.
/// Use this for LINQ and Entity Framework query projections.
/// </summary>
/// <value>An expression tree that can be used in LINQ queries for efficient database projections.</value>
/// <example>
/// <code>
/// var dtos = context.Persons
/// .Where(x => x.IsActive)
/// .Select(PersonDto.Projection)
/// .ToList();
/// </code>
/// </example>
public static Expression<Func<global::MapperDemo.Person, PersonDto>> Projection =>
source => new PersonDto
{
Id = source.Id,
FirstName = source.FirstName,
LastName = source.LastName
};
}
Useful
Download Example (.NET C#)
Share DotNetBrightener.Mapper
https://ignatandrei.github.io/RSCG_Examples/v2/docs/DotNetBrightener.Mapper
Category "Mapper" has the following generators:
1 AutoDTO
2023-08-24
2 AutoGen
2024-02-22
3 DapperFluentMap
2026-11-13
4 DevSource.ObjectMapping
2026-11-16
5 DotNetBrightener.Mapper
2026-11-14
6 DynamicsMapper
2023-10-16
7 Facet
2025-08-17
8 GenericDtoSourceGenerator
2026-11-24
9 LightweightObjectMapper
2024-09-18
10 lomapper
2026-04-07
11 MagicMap
2023-10-08
12 MapItEasy
2026-09-10
13 Mappa.Generator
2026-10-03
14 mapperly
2023-04-16
15 MapTo
2023-10-05
16 Najlot.Map.SourceGenerator
2026-08-29
17 NextGenMapper
2023-08-16
18 Synthetix
2026-11-18