Skip to main content

DotNetBrightener.Mapper by Vampire Coder

NuGet / site data​

Nuget GitHub last commit GitHub Repo stars

Details​

Info​

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​

note

Vampire Coder Alt text

Original Readme​

note

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​

note

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)​

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>

Generated Files​

Those are taken from $(BaseIntermediateOutputPath)\GX

// <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 Nuget GitHub Repo stars 2023-08-24

2 AutoGen Nuget GitHub Repo stars 2024-02-22

3 DapperFluentMap Nuget GitHub Repo stars 2026-11-13

4 DevSource.ObjectMapping Nuget GitHub Repo stars 2026-11-16

5 DotNetBrightener.Mapper Nuget GitHub Repo stars 2026-11-14

6 DynamicsMapper Nuget GitHub Repo stars 2023-10-16

7 Facet Nuget GitHub Repo stars 2025-08-17

8 GenericDtoSourceGenerator Nuget GitHub Repo stars 2026-11-24

9 LightweightObjectMapper Nuget GitHub Repo stars 2024-09-18

10 lomapper Nuget GitHub Repo stars 2026-04-07

11 MagicMap Nuget GitHub Repo stars 2023-10-08

12 MapItEasy Nuget GitHub Repo stars 2026-09-10

13 Mappa.Generator Nuget GitHub Repo stars 2026-10-03

14 mapperly Nuget GitHub Repo stars 2023-04-16

15 MapTo Nuget GitHub Repo stars 2023-10-05

16 Najlot.Map.SourceGenerator Nuget GitHub Repo stars 2026-08-29

17 NextGenMapper Nuget GitHub Repo stars 2023-08-16

18 Synthetix Nuget GitHub Repo stars 2026-11-18

See category​

Mapper