Synthetix by Nertti Technologies
NuGet / site data
Details
Info
Name: Synthetix
A compile-time, source-generated object-to-object mapper for .NET. As fast as hand-written code, AOT friendly, with an auditable, drift-checked mapping manifest.
Author: Nertti Technologies
NuGet: https://www.nuget.org/packages/Synthetix/
You can find more details at https://github.com/Nertti-Technologies/Synthetix
Author
Nertti Technologies

Original Readme

A compile-time, source-generated object-to-object mapper for .NET — as fast as hand-written code, with mappings that are auditable and drift-checked.
Synthetix turns the boring, error-prone job of copying values from one object to
another into plain C# that the compiler writes for you. You declare a partial
mapper class; a Roslyn source generator reads your types at build time and emits
ordinary, readable mapping code into your project.
Because the mapping is generated while your project compiles, there is no runtime reflection, no expression-tree compilation, and no startup warm-up. The generated code is real C# you can set a breakpoint inside, and it works under Native AOT and assembly trimming with nothing extra to configure.
Synthetix focuses its effort on one thing those tools leave largely untouched: making the mapping itself something you can see, review, and trust — see the mapping manifest below.
Install
<PackageReference Include="Synthetix" Version="0.1.0"
PrivateAssets="all" ExcludeAssets="runtime" />
The package contains only a source generator. Your built assembly carries no Synthetix dependency at runtime — nothing to load, trim, or version-conflict.
Quick start
Declare a mapper. The methods are partial and have no body — Synthetix fills
them in:
using Synthetix;
[Mapper]
public partial class OrderMapper
{
public partial OrderDto ToDto(Order order);
}
That is all. Call new OrderMapper().ToDto(order) and you get a fully mapped
OrderDto. If a property cannot be mapped, your build fails with a precise
error instead of shipping a silent null.
What Synthetix does
- Same-name mapping — properties with matching names and compatible types are mapped automatically.
- Flattening / unflattening —
Order.Customer.Namemaps toOrderCustomerNameand back, by naming convention. - Compile-time diagnostics — broken, incomplete, or ambiguous mappings
become compiler errors and warnings (
SYNTX001–SYNTX017) with exact source locations. - Custom member configuration — attributes to rename, ignore, supply constant values, or route a member through your own conversion method.
- The mapping manifest — the capability Synthetix invests in most.
The mapping manifest
For every mapper, Synthetix writes a mapping manifest — a readable record of every mapping decision (which source fed which target, which rule resolved it, what was ignored, and a coverage count). It is meant to be committed to source control, so a mapping becomes something a reviewer can read in a pull request.
On every build, Synthetix compares your committed manifest against the current
mapping. If they differ — a newly unmapped field, a changed rule — it reports
SYNTX017. Teams keep that a warning locally and an error in CI, so a change in
mapping behaviour can never merge by accident. Refresh the manifest explicitly
with:
dotnet build -t:SynthetixUpdateManifest
The manifest is on by default. Turn it off with
<SynthetixManifest>false</SynthetixManifest>.
Build from source
This repository contains the full solution (see docs/Synthetix-Design.md for
the design):
dotnet build Synthetix.sln
dotnet test Synthetix.sln
dotnet run --project samples/Synthetix.Sample
Requires the .NET 10 SDK. The generator project itself targets netstandard2.0
because it is loaded into the compiler — that is a hard requirement, separate
from the .NET 10 your own code targets.
License
Apache 2.0 — see LICENSE.
About
Generating audited object-to-object mapping code
How to use
Example (source csproj, source files)
- CSharp Project
- Program.cs
- Models.cs
- PersonMapper.cs
This is the CSharp Project that references Synthetix
<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="Synthetix" Version="0.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
This is the use of Synthetix in Program.cs
using SynthetixDemo;
var person = new Person
{
Id = 42,
Name = "Ignat Andrei",
Email = "ignatandrei@yahoo.com",
Address = new Address
{
City = "Bucarest",
Country = "Romania"
}
};
var mapper = new PersonMapper();
PersonDto dto = mapper.ToDto(person);
Console.WriteLine($"Id: {dto.Id}");
Console.WriteLine($"Name: {dto.Name}");
Console.WriteLine($"Email: {dto.Email}");
Console.WriteLine($"City: {dto.AddressCity}");
Console.WriteLine($"Country: {dto.AddressCountry}");
This is the use of Synthetix in Models.cs
namespace SynthetixDemo;
public sealed class Person
{
public int Id \{ get; set; }
public string Name \{ get; set; \} = string.Empty;
public string Email \{ get; set; \} = string.Empty;
public Address Address \{ get; set; \} = new();
}
public sealed class Address
{
public string City \{ get; set; \} = string.Empty;
public string Country \{ get; set; \} = string.Empty;
}
public sealed class PersonDto
{
public int Id \{ get; set; }
public string Name \{ get; set; \} = string.Empty;
public string Email \{ get; set; \} = string.Empty;
public string AddressCity \{ get; set; \} = string.Empty;
public string AddressCountry \{ get; set; \} = string.Empty;
}
This is the use of Synthetix in PersonMapper.cs
using Synthetix;
namespace SynthetixDemo;
[Mapper]
public partial class PersonMapper
{
public partial PersonDto ToDto(Person person);
}
Generated Files
Those are taken from $(BaseIntermediateOutputPath)\GX
- OrderMapper.g.cs
- OrderMapper.Manifest.g.cs
- PersonMapper.g.cs
- PersonMapper.Manifest.g.cs
- Synthetix.Attributes.g.cs
// <auto-generated/> This file was produced by Synthetix. Do not edit it.
#nullable enable
namespace SynthetixDemo
{
public partial class OrderMapper
{
public partial global::SynthetixDemo.OrderDto ToDto(global::SynthetixDemo.Order order)
{
var target = new global::SynthetixDemo.OrderDto();
target.Id = order.Id;
target.DisplayTotal = FormatMoney(order.Total);
target.CustomerName = order.Customer.Name;
target.CustomerEmail = order.Customer.Email;
return target;
}
}
}
// <auto-generated/> Synthetix manifest carrier for OrderMapper.
// It stores the mapping manifest as comments so the 'SynthetixUpdateManifest'
// build target can write the readable mapping/ files. It has no executable code.
//SYNTHETIX-MANIFEST-BEGIN name=OrderMapper format=json
//{
// "mapper": "OrderMapper",
// "methods": [
// {
// "name": "ToDto",
// "source": "global::SynthetixDemo.Order",
// "target": "global::SynthetixDemo.OrderDto",
// "coverage": \{ "mapped": 4, "ignored": 0, "unmapped": 0 },
// "mappings": [
// \{ "target": "Id", "source": "order.Id", "rule": "same-name" },
// \{ "target": "DisplayTotal", "source": "FormatMoney(order.Total)", "rule": "[MapProperty Use]" },
// \{ "target": "CustomerName", "source": "order.Customer.Name", "rule": "flatten path" },
// \{ "target": "CustomerEmail", "source": "order.Customer.Email", "rule": "flatten path" }
// ],
// "ignoredTargets": [],
// "ignoredSources": []
// \} ]
//}
//
//SYNTHETIX-MANIFEST-END
//SYNTHETIX-MANIFEST-BEGIN name=OrderMapper format=md
//# Mapping manifest - OrderMapper
//
//_Generated by Synthetix. Run `dotnet build -t:SynthetixUpdateManifest` to refresh._
//
//## SynthetixDemo.OrderDto ToDto(SynthetixDemo.Order order)
//
//**Coverage:** 4 / 4 target members
//
//| Target | Source | Rule |
//|---------------|--------------------------|-------------------|
//| Id | order.Id | same-name |
//| DisplayTotal | FormatMoney(order.Total) | [MapProperty Use] |
//| CustomerName | order.Customer.Name | flatten path |
//| CustomerEmail | order.Customer.Email | flatten path |
//
//SYNTHETIX-MANIFEST-END
// <auto-generated/> This file was produced by Synthetix. Do not edit it.
#nullable enable
namespace SynthetixDemo
{
public partial class PersonMapper
{
public partial global::SynthetixDemo.PersonDto ToDto(global::SynthetixDemo.Person person)
{
var target = new global::SynthetixDemo.PersonDto();
target.Id = person.Id;
target.Name = person.Name;
target.Email = person.Email;
target.AddressCity = person.Address.City;
target.AddressCountry = person.Address.Country;
return target;
}
}
}
// <auto-generated/> Synthetix manifest carrier for PersonMapper.
// It stores the mapping manifest as comments so the 'SynthetixUpdateManifest'
// build target can write the readable mapping/ files. It has no executable code.
//SYNTHETIX-MANIFEST-BEGIN name=PersonMapper format=json
//{
// "mapper": "PersonMapper",
// "methods": [
// {
// "name": "ToDto",
// "source": "global::SynthetixDemo.Person",
// "target": "global::SynthetixDemo.PersonDto",
// "coverage": \{ "mapped": 5, "ignored": 0, "unmapped": 0 },
// "mappings": [
// \{ "target": "Id", "source": "person.Id", "rule": "same-name" },
// \{ "target": "Name", "source": "person.Name", "rule": "same-name" },
// \{ "target": "Email", "source": "person.Email", "rule": "same-name" },
// \{ "target": "AddressCity", "source": "person.Address.City", "rule": "flatten path" },
// \{ "target": "AddressCountry", "source": "person.Address.Country", "rule": "flatten path" }
// ],
// "ignoredTargets": [],
// "ignoredSources": []
// \} ]
//}
//
//SYNTHETIX-MANIFEST-END
//SYNTHETIX-MANIFEST-BEGIN name=PersonMapper format=md
//# Mapping manifest - PersonMapper
//
//_Generated by Synthetix. Run `dotnet build -t:SynthetixUpdateManifest` to refresh._
//
//## SynthetixDemo.PersonDto ToDto(SynthetixDemo.Person person)
//
//**Coverage:** 5 / 5 target members
//
//| Target | Source | Rule |
//|----------------|------------------------|--------------|
//| Id | person.Id | same-name |
//| Name | person.Name | same-name |
//| Email | person.Email | same-name |
//| AddressCity | person.Address.City | flatten path |
//| AddressCountry | person.Address.Country | flatten path |
//
//SYNTHETIX-MANIFEST-END
// <auto-generated/>
// This file was injected into your project by the Synthetix source generator.
// It defines the attributes used to declare and configure mappers.
// Do not edit it - any change is overwritten on the next build.
#nullable enable
namespace Synthetix
{
using System;
/// <summary>How property names are compared during same-name matching.</summary>
internal enum PropertyNameMatching
{
/// <summary>Names must match exactly, including upper/lower case.</summary>
Exact = 0,
/// <summary>Names match even when the upper/lower case is different.</summary>
IgnoreCase = 1,
}
/// <summary>How loudly the generator reports an unmapped member.</summary>
internal enum MemberMappingSeverity
{
/// <summary>Report it as a build error.</summary>
Error = 0,
/// <summary>Report it as a build warning.</summary>
Warn = 1,
/// <summary>Say nothing about it.</summary>
Ignore = 2,
}
/// <summary>What generated code does when a step on a nested path is null.</summary>
internal enum NullHandling
{
/// <summary>Let the null flow through, so the target member becomes null.</summary>
Propagate = 0,
/// <summary>Throw an exception that names the null step.</summary>
Throw = 1,
/// <summary>Use the default value for the target member's type.</summary>
UseDefault = 2,
}
/// <summary>
/// Marks a partial class or struct as a Synthetix mapper. The generator
/// fills in the body of every partial mapping method it declares.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
internal sealed class MapperAttribute : Attribute
{
/// <summary>
/// When true, every target member must be explicitly mapped or ignored.
/// An unaccounted-for target member becomes the error SYNTX013.
/// </summary>
public bool RequireExplicitMapping \{ get; set; }
/// <summary>How source and target property names are compared.</summary>
public PropertyNameMatching NameMatching \{ get; set; \} = PropertyNameMatching.Exact;
/// <summary>Whether the flattening / unflattening convention is on.</summary>
public bool EnableFlattening \{ get; set; \} = true;
/// <summary>Severity for a target member that has no source (SYNTX004).</summary>
public MemberMappingSeverity UnmappedTargetMember \{ get; set; \} = MemberMappingSeverity.Warn;
/// <summary>Severity for a source member that is never used (SYNTX005).</summary>
public MemberMappingSeverity UnmappedSourceMember \{ get; set; \} = MemberMappingSeverity.Ignore;
/// <summary>How enum member names are compared when mapping enum to enum.</summary>
public PropertyNameMatching EnumNameMatching \{ get; set; \} = PropertyNameMatching.Exact;
/// <summary>How a null along a flatten / unflatten path is handled.</summary>
public NullHandling NullPathHandling \{ get; set; \} = NullHandling.Propagate;
/// <summary>When true, allows opt-in conversions between string and primitive types.</summary>
public bool EnableStringConversions \{ get; set; }
}
/// <summary>
/// Maps one source member to one target member. Use it to rename a member,
/// to state an explicit nested path, or to route a value through a converter.
/// </summary>
/// <example><code>[MapProperty("Customer.Name", "CustomerName")]</code></example>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
internal sealed class MapPropertyAttribute : Attribute
{
/// <param name="source">The source member name, or a dotted path such as "Customer.Name".</param>
/// <param name="target">The target member name.</param>
public MapPropertyAttribute(string source, string target)
{
Source = source;
Target = target;
}
/// <summary>The source member name or dotted path.</summary>
public string Source \{ get; }
/// <summary>The target member name.</summary>
public string Target \{ get; }
/// <summary>
/// Optional. The name of a method in the mapper that converts the source
/// value into the target value.
/// </summary>
public string? Use \{ get; set; }
}
/// <summary>
/// Leaves a target member unset. This also suppresses SYNTX004 and SYNTX013
/// for that member.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
internal sealed class MapperIgnoreTargetAttribute : Attribute
{
/// <param name="target">The target member to leave unset.</param>
public MapperIgnoreTargetAttribute(string target) => Target = target;
/// <summary>The target member that is deliberately not mapped.</summary>
public string Target \{ get; }
}
/// <summary>
/// Marks a source member as intentionally unused. This suppresses SYNTX005
/// for that member.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
internal sealed class MapperIgnoreSourceAttribute : Attribute
{
/// <param name="source">The source member to mark as unused.</param>
public MapperIgnoreSourceAttribute(string source) => Source = source;
/// <summary>The source member that is deliberately not read.</summary>
public string Source \{ get; }
}
/// <summary>
/// Assigns a fixed value to a target member, independent of the source.
/// Supply either a constant <see cref="Value"/> or a <see cref="Use"/> method.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
internal sealed class MapValueAttribute : Attribute
{
/// <param name="target">The target member to fill.</param>
public MapValueAttribute(string target) => Target = target;
/// <summary>The target member that receives the fixed value.</summary>
public string Target \{ get; }
/// <summary>A compile-time constant value to assign.</summary>
public object? Value \{ get; set; }
/// <summary>The name of a method that produces the value to assign.</summary>
public string? Use \{ get; set; }
}
/// <summary>
/// Registers one derived-type pair for a polymorphic mapping. Put it on a
/// mapping method whose source is a base type; the generator then inspects
/// the runtime type and dispatches to the matching derived mapping.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
internal sealed class MapDerivedTypeAttribute : Attribute
{
/// <param name="sourceType">A type that derives from the mapping's source type.</param>
/// <param name="targetType">The matching type that derives from the mapping's target type.</param>
public MapDerivedTypeAttribute(Type sourceType, Type targetType)
{
SourceType = sourceType;
TargetType = targetType;
}
/// <summary>The derived source type.</summary>
public Type SourceType \{ get; }
/// <summary>The derived target type it is mapped to.</summary>
public Type TargetType \{ get; }
}
/// <summary>
/// Marks a normal method inside the mapper as a conversion the generator may
/// call. Use it to force discovery of a method, or to exclude one with
/// <see cref="Ignore"/> = true.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
internal sealed class UserMappingAttribute : Attribute
{
/// <summary>When true, the generator never uses this method as a mapping.</summary>
public bool Ignore \{ get; set; }
}
}
Useful
Download Example (.NET C#)
Share Synthetix
https://ignatandrei.github.io/RSCG_Examples/v2/docs/Synthetix
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