From 50168cf1d8be370b9801f2c6007e67b7b6062dbf Mon Sep 17 00:00:00 2001 From: Andrei Ignat Date: Wed, 2 Sep 2026 19:33:35 +0300 Subject: [PATCH 1/2] example --- README.md | 30 +- later.md | 2 +- v2/.tours/Najlot.Map.SourceGenerator.tour | 48 ++ v2/Generator/all.csv | 1 + v2/RSCGExamplesData/GeneratorDataRec.json | 7 + .../description.json | 22 + .../Najlot.Map.SourceGenerator/nuget.txt | 1 + .../Najlot.Map.SourceGenerator/readme.txt | 263 +++++++++ .../src/mapperDemo.slnx | 3 + .../src/mapperDemo/Person.cs | 8 + .../src/mapperDemo/PersonDTO.cs | 23 + .../src/mapperDemo/Program.cs | 10 + .../src/mapperDemo/mapperDemo.csproj | 25 + .../Najlot.Map.SourceGenerator/video.json | 39 ++ v2/rscg_examples_site/docs/Authors/Najlot.md | 4 +- .../docs/Categories/Mapper.md | 6 +- .../docs/Categories/_PrimitiveMapper.mdx | 4 +- .../Najlot.Map.SourceGenerator.md | 514 ++++++++++++++++++ .../docs/RSCG-Examples/index.md | 13 +- v2/rscg_examples_site/docs/about.md | 2 +- v2/rscg_examples_site/docs/indexRSCG.md | 5 +- .../src/components/HomepageFeatures/index.js | 2 +- .../static/exports/RSCG.json | 8 + .../static/exports/RSCG.xlsx | Bin 14990 -> 15025 bytes 24 files changed, 1024 insertions(+), 16 deletions(-) create mode 100644 v2/.tours/Najlot.Map.SourceGenerator.tour create mode 100644 v2/rscg_examples/Najlot.Map.SourceGenerator/description.json create mode 100644 v2/rscg_examples/Najlot.Map.SourceGenerator/nuget.txt create mode 100644 v2/rscg_examples/Najlot.Map.SourceGenerator/readme.txt create mode 100644 v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo.slnx create mode 100644 v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/Person.cs create mode 100644 v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/PersonDTO.cs create mode 100644 v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/Program.cs create mode 100644 v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/mapperDemo.csproj create mode 100644 v2/rscg_examples/Najlot.Map.SourceGenerator/video.json create mode 100644 v2/rscg_examples_site/docs/RSCG-Examples/Najlot.Map.SourceGenerator.md diff --git a/README.md b/README.md index d3304c8eb..6a58ae779 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# RSCG - 287 Examples of Roslyn Source Code Generators / 16 created by Microsoft / +# RSCG - 288 Examples of Roslyn Source Code Generators / 16 created by Microsoft / -The RSCG_Examples repository is a comprehensive documentation system that automatically processes and showcases 287 Roslyn Source Code Generator (RSCG) examples. The system transforms individual RSCG projects into structured documentation with code examples and cross-referenced content with a searchable website and code example exports. +The RSCG_Examples repository is a comprehensive documentation system that automatically processes and showcases 288 Roslyn Source Code Generator (RSCG) examples. The system transforms individual RSCG projects into structured documentation with code examples and cross-referenced content with a searchable website and code example exports. This system serves as both a learning resource for .NET developers interested in source generators and an automated pipeline for maintaining up-to-date documentation about the RSCG ecosystem -## Latest Update : 2026-08-28 => 28 August 2026 +## Latest Update : 2026-08-29 => 29 August 2026 If you want to see examples with code, please click ***[List V2](https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG)*** @@ -24,8 +24,30 @@ If you want to be notified each time I add a new RSCG example , please click htt ## Content -Those are the 287 Roslyn Source Code Generators that I have tested you can see and download source code example. +Those are the 288 Roslyn Source Code Generators that I have tested you can see and download source code example. ( including 16 from Microsoft ) +### 288. [Najlot.Map.SourceGenerator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/Najlot.Map.SourceGenerator) , in the [Mapper](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mapper) category + +Generated on : 2026-08-29 => 29 August 2026 + +
+ Expand + + + +Author: Najlot + +Source generator for Najlot.Map that provides automatic mapping code generation with high performance caching. + +Nuget: [https://www.nuget.org/packages/Najlot.Map.SourceGenerator/](https://www.nuget.org/packages/Najlot.Map.SourceGenerator/) + + +Link: [https://ignatandrei.github.io/RSCG_Examples/v2/docs/Najlot.Map.SourceGenerator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/Najlot.Map.SourceGenerator) + +Source: [https://github.com/najlot/Map](https://github.com/najlot/Map) + +
+ ### 287. [TrimItEasy](https://ignatandrei.github.io/RSCG_Examples/v2/docs/TrimItEasy) , in the [EnhancementClass](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementclass) category Generated on : 2026-08-28 => 28 August 2026 diff --git a/later.md b/later.md index 5c92ff14f..cab8ff57a 100644 --- a/later.md +++ b/later.md @@ -1,6 +1,6 @@ # Just later -## Latest Update : 2026-08-28 => 28 August 2026 +## Latest Update : 2026-08-29 => 29 August 2026 diff --git a/v2/.tours/Najlot.Map.SourceGenerator.tour b/v2/.tours/Najlot.Map.SourceGenerator.tour new file mode 100644 index 000000000..eb1b70b14 --- /dev/null +++ b/v2/.tours/Najlot.Map.SourceGenerator.tour @@ -0,0 +1,48 @@ + +{ + "$schema": "https://aka.ms/codetour-schema", + "title": "Najlot.Map.SourceGenerator", + "steps": + [ + { + "file": "rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/mapperDemo.csproj", + "description": "First, we add Nuget [Najlot.Map.SourceGenerator](https://www.nuget.org/packages/Najlot.Map.SourceGenerator/) in csproj ", + "pattern": "Najlot.Map.SourceGenerator" + } + + ,{ + "file": "rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/PersonDTO.cs", + "description": "File PersonDTO.cs ", + "pattern": "this is the code" + } + + ,{ + "file": "rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/Person.cs", + "description": "File Person.cs ", + "pattern": "this is the code" + } + + ,{ + "file": "rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/Program.cs", + "description": "File Program.cs \r\n>> dotnet run --project rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/mapperDemo.csproj ", + "pattern": "this is the code" + } + + + ,{ + "file": "rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/obj/GX/Najlot.Map.SourceGenerator/Najlot.Map.SourceGenerator.RegistrationGenerator/MapRegistrationExtensions_mapperDemo.g.cs", + "description": "Generated File 2 from 2 : MapRegistrationExtensions_mapperDemo.g.cs ", + "line": 1 + } + + ,{ + "file": "rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/obj/GX/Najlot.Map.SourceGenerator/Najlot.Map.SourceGenerator.MappingGenerator/mapperDemo_UserMapper.g.cs", + "description": "Generated File 1 from 2 : mapperDemo_UserMapper.g.cs ", + "line": 1 + } + + ], + + "ref": "main" + +} \ No newline at end of file diff --git a/v2/Generator/all.csv b/v2/Generator/all.csv index 7a2489f21..aa542727a 100644 --- a/v2/Generator/all.csv +++ b/v2/Generator/all.csv @@ -286,3 +286,4 @@ Nr,Key,Source,Category 285,PropertyResolvers, https://github.com/tombiddulph/PropertyResolvers,EnhancementProject 286,SatorImaging.TDoubles, https://github.com/sator-imaging/TDoubles,Tests 287,TrimItEasy, https://github.com/phongnguyend/TrimItEasy,EnhancementClass +288,Najlot.Map.SourceGenerator, https://github.com/najlot/Map,Mapper diff --git a/v2/RSCGExamplesData/GeneratorDataRec.json b/v2/RSCGExamplesData/GeneratorDataRec.json index f5a56d8d8..a7cce867e 100644 --- a/v2/RSCGExamplesData/GeneratorDataRec.json +++ b/v2/RSCGExamplesData/GeneratorDataRec.json @@ -1740,5 +1740,12 @@ "dtStart": "2026-08-28T00:00:00", "show": true } + , + { + "ID":"Najlot.Map.SourceGenerator", + "Category": 6, + "dtStart": "2026-08-29T00:00:00", + "show": true + } ] \ No newline at end of file diff --git a/v2/rscg_examples/Najlot.Map.SourceGenerator/description.json b/v2/rscg_examples/Najlot.Map.SourceGenerator/description.json new file mode 100644 index 000000000..9a196785f --- /dev/null +++ b/v2/rscg_examples/Najlot.Map.SourceGenerator/description.json @@ -0,0 +1,22 @@ +{ + "generator":{ + "name":"Najlot.Map.SourceGenerator", + "nuget":[ + "https://www.nuget.org/packages/Najlot.Map.SourceGenerator/" + ], + "link":"https://github.com/najlot/Map", + "author":"Najlot", + "source":"https://github.com/najlot/Map" + }, + "data":{ + "goodFor":[" Generates object mapping code at compile time using source generators"], + "csprojDemo":"mapperDemo.csproj", + "csFiles":["Program.cs","Person.cs","PersonDTO.cs"], + "excludeDirectoryGenerated":[""], + "includeAdditionalFiles":[""] + }, + "links":{ + "blog":"", + "video":"" + } +} \ No newline at end of file diff --git a/v2/rscg_examples/Najlot.Map.SourceGenerator/nuget.txt b/v2/rscg_examples/Najlot.Map.SourceGenerator/nuget.txt new file mode 100644 index 000000000..f027bdca3 --- /dev/null +++ b/v2/rscg_examples/Najlot.Map.SourceGenerator/nuget.txt @@ -0,0 +1 @@ +Source generator for Najlot.Map that provides automatic mapping code generation with high performance caching. \ No newline at end of file diff --git a/v2/rscg_examples/Najlot.Map.SourceGenerator/readme.txt b/v2/rscg_examples/Najlot.Map.SourceGenerator/readme.txt new file mode 100644 index 000000000..ee66eb2bf --- /dev/null +++ b/v2/rscg_examples/Najlot.Map.SourceGenerator/readme.txt @@ -0,0 +1,263 @@ +# ![M](https://github.com/najlot/Map/blob/main/images/icon.png) Najlot.Map + +Najlot.Map is a high-performance object mapping library for .NET built around explicit mapping methods. +Instead of convention-heavy auto-mapping, it keeps mapping logic in normal C# methods so behavior stays readable, predictable, and easy to review. +When you want less boilerplate, you can add the optional source generator and keep the same programming model. + +Najlot.Map is a good fit when you want: + +* explicit mappings instead of hidden conventions, +* strong runtime performance without magic in the hot path, +* a single `IMap` entry point for object, collection, async, and queryable mapping, +* the option to scale from handwritten methods to generated mappings. + +--- + +## Why Najlot.Map + +* Unlike convention-based mappers, mapping behavior lives in regular C# methods you can read, debug, and review directly. +* Unlike tools that rely on runtime magic, Najlot.Map keeps the hot path explicit and lets you add source generation only when it helps. +* Unlike broad auto-mapping defaults, it favors predictable registrations and validation so mapping changes are easier to catch in tests or startup checks. + +--- + +## What It Does + +* Explicit method-based mappings +* Central `IMap` container +* Object, collection, nullable, and async enumerable mapping +* `IQueryable` projections through expressions +* Optional Roslyn source generator +* Validation for delegate-based mappings in tests +* Factory-based object creation for DI or custom activation + +--- + +## Packages + +Najlot.Map is distributed as two NuGet packages: + +| Package | Description | +| --- | --- | +| `Najlot.Map` | Core runtime, attributes, registration, validation, and mapping APIs | +| `Najlot.Map.SourceGenerator` | Optional compile-time generation for mapping methods and registration | + +--- + +## Installation + +Install the runtime package: + +```bash +dotnet add package Najlot.Map +``` + +Add the source generator when you want compile-time generated mappings: + +```bash +dotnet add package Najlot.Map.SourceGenerator +``` + +--- + +## Core Model + +* Mappings are regular methods, not configuration files. +* `IMap` is the single entry point for registration and execution. +* Public mapping methods can be discovered and registered automatically. +* Generated mappings follow the same runtime API as handwritten mappings. +* Validation is meant for tests and startup checks, not the request path. + +--- + +## Quick Start + +### 1. Write mapping methods + +```csharp +using Najlot.Map; +using Najlot.Map.Attributes; + +internal class UserMappings +{ + [MapIgnoreProperty(nameof(User.Password))] + public void MapModelToUser(IMap map, UserModel from, User to) + { + to.Id = from.Id; + to.Username = from.Username; + to.Features = map + .From(from.Features) + .ToList(); + } + + [MapIgnoreProperty(nameof(UserModel.Password))] + public UserModel MapUserToModel(IMap map, User from) => new() + { + Id = from.Id, + Username = from.Username, + Features = map + .From(from.Features) + .To() + }; + + [MapIgnoreMethod] + public Guid IgnoredMethod(UserModel from) => from.Id; +} +``` + +### 2. Register the mappings + +```csharp +var map = new Map() + .Register(); +``` + +If your mapping classes need custom construction, register a factory: + +```csharp +var map = new Map() + .RegisterFactory(type => serviceProvider.GetRequiredService(type)) + .Register(); +``` + +### 3. Map objects and collections + +```csharp +var user = map.From(userModel).To(); +var users = map.From(userModels).To().ToList(); +``` + +--- + +## Registration Options + +### Manual registration + +Register a class and let Najlot.Map inspect its public methods: + +```csharp +var map = new Map() + .Register(); +``` + +Supported method shapes include: + +```csharp +void Map(TFrom from, TTo to) +void Map(IMap map, TFrom from, TTo to) +TTo Map(TFrom from) +TTo Map(IMap map, TFrom from) +Expression> Projection() +``` + +### Generated registration + +When using `Najlot.Map.SourceGenerator`, classes marked with `[Mapping]` get picked up and the generator emits an assembly-specific extension method named `Register{AssemblyName}Mappings()`. + +```csharp +var map = new Map() + .RegisterMyProjectMappings(); +``` + +If generated mapping classes need constructor injection, the same `RegisterFactory(...)` hook applies. + +--- + +## Source Generator + +The source generator keeps the same explicit programming model while removing repetitive mapping code. + +```csharp +using Najlot.Map; +using Najlot.Map.Attributes; + +[Mapping] +public partial class UserMappings +{ + public partial void MapUser(IMap map, UserModel from, User to); + public partial void MapFeature(IMap map, UserFeatureModel from, UserFeature to); + + public DateTime ConvertToUtc(DateTimeOffset offset) => offset.UtcDateTime; +} +``` + +Usage: + +```csharp +var map = new Map() + .RegisterMyProjectMappings(); + +var user = map.From(userModel).To(); +``` + +Use the generator when you want to reduce boilerplate but still keep mappings explicit, typed, and reviewable. + +--- + +## Validation + +`Validate()` checks registered delegate-based mappings and throws `MapMissPropertiesException` when destination properties are left unmapped and not explicitly ignored. + +```csharp +var map = new Map() + .Register(); + +map.Validate(); +``` + +Recommended usage: + +* unit tests, +* integration tests, +* application startup checks. + +Validation does not cover expression-based mappings used for `IQueryable` projections. + +--- + +## Queryable Projections + +For `IQueryable` scenarios such as Entity Framework Core, register an expression mapping so the provider can translate it. + +```csharp +using System.Linq.Expressions; +using Najlot.Map.Attributes; + +[Mapping] +public partial class UserMappings +{ + public static partial Expression> ToListItem(); +} +``` + +Usage: + +```csharp +var map = new Map() + .RegisterMyProjectMappings(); + +var query = map.From(db.Users).To(); +var items = await query.ToListAsync(); +``` + +Use delegate mappings for in-memory object graphs. +Use expression mappings when the projection needs to stay provider-translatable. + +--- + +## Design Principles + +Najlot.Map is intentionally not a convention-over-configuration auto-mapper. +Its value is in making mappings obvious and controllable while still giving you enough tooling to keep the codebase fast and maintainable as it grows. + +That means: + +* explicit code over implicit behavior, +* predictable runtime behavior over hidden fallback rules, +* optional generation over mandatory framework ceremony. + +--- + +## License + +MIT License \ No newline at end of file diff --git a/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo.slnx b/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo.slnx new file mode 100644 index 000000000..6712d745c --- /dev/null +++ b/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo.slnx @@ -0,0 +1,3 @@ + + + diff --git a/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/Person.cs b/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/Person.cs new file mode 100644 index 000000000..c1c18c040 --- /dev/null +++ b/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/Person.cs @@ -0,0 +1,8 @@ + +public partial class Person +{ + public int ID { get; set; } + public string? FirstName { get; set; } + public string? LastName { get; set; } +} + diff --git a/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/PersonDTO.cs b/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/PersonDTO.cs new file mode 100644 index 000000000..4607bc62f --- /dev/null +++ b/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/PersonDTO.cs @@ -0,0 +1,23 @@ +using Najlot.Map; +using Najlot.Map.Attributes; +namespace mapperDemo; +public partial struct PersonDTO +{ + public string? FirstName { get; set; } + public string? LastName { get; set; } + + public string FullName { + get + { + return FirstName + " " + LastName; + } + } +} + + +[Mapping] +public partial class UserMapper +{ + [MapIgnoreProperty(nameof(Person.ID))] + public partial PersonDTO MapUser(Person from); +} \ No newline at end of file diff --git a/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/Program.cs b/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/Program.cs new file mode 100644 index 000000000..b40c2942c --- /dev/null +++ b/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/Program.cs @@ -0,0 +1,10 @@ +using mapperDemo; +using Najlot.Map; +var map = new Map(); +map.RegistermapperDemoMappings(); +map.Validate(); +var p=new Person(); +p.FirstName = "Andrei"; +p.LastName = "Ignat"; +PersonDTO personDTO=map.From(p).To(); +Console.WriteLine(personDTO.FullName); diff --git a/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/mapperDemo.csproj b/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/mapperDemo.csproj new file mode 100644 index 000000000..8d50d2b82 --- /dev/null +++ b/v2/rscg_examples/Najlot.Map.SourceGenerator/src/mapperDemo/mapperDemo.csproj @@ -0,0 +1,25 @@ + + + + Exe + net10.0 + enable + enable + + + + true + $(BaseIntermediateOutputPath)\GX + + + + + + + + + + + + + diff --git a/v2/rscg_examples/Najlot.Map.SourceGenerator/video.json b/v2/rscg_examples/Najlot.Map.SourceGenerator/video.json new file mode 100644 index 000000000..2db5e28a1 --- /dev/null +++ b/v2/rscg_examples/Najlot.Map.SourceGenerator/video.json @@ -0,0 +1,39 @@ +{ + "scriptName": "Najlot.Map.SourceGenerator", + "steps": +[ + {"typeStep":"exec","arg":"clipchamp.exe launch"}, + {"typeStep":"text","arg": "Welcome to Roslyn Examples"}, + {"typeStep":"text","arg":"If you want to see more examples , see List Of RSCG"}, + {"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG"}, + {"typeStep":"text","arg": "My name is Andrei Ignat and I am deeply fond of Roslyn Source Code Generator. "}, + +{"typeStep":"text","arg": "Today I will present Najlot.Map.SourceGenerator . Generates object mapping code at compile time using source generators ."}, +{"typeStep":"browser","arg":"https://www.nuget.org/packages/Najlot.Map.SourceGenerator/"}, +{"typeStep":"text","arg": "The whole example is here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/Najlot.Map.SourceGenerator"}, +{"typeStep":"text","arg": "You can download the code from here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/Najlot.Map.SourceGenerator#download-example-net--c-"}, +{"typeStep":"text","arg":"Here is the code downloaded "}, +{"typeStep":"exec","arg":"explorer.exe /select,D:\\gth\\RSCG_Examples\\v2\\Generator.sln"}, +{"typeStep":"text","arg": "So , let's start the project with Visual Studio Code "}, +{"typeStep":"stepvscode","arg": "-n D:\\gth\\RSCG_Examples\\v2"}, + +{"typeStep":"text","arg": "To use it ,you will put the Nuget Najlot.Map.SourceGenerator into the csproj "}, + +{"typeStep":"stepvscode","arg": "-r -g D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\Najlot.Map.SourceGenerator\\src\\mapperDemo\\mapperDemo.csproj"}, + +{"typeStep":"text","arg": "And now I will show you an example of using Najlot.Map.SourceGenerator"}, + +{"typeStep":"hide","arg": "now execute the tour in VSCode"}, +{"typeStep":"tour", "arg": "src/.tours/"}, +{"typeStep":"text","arg":" And I will execute the project"}, +{"typeStep":"showproj", "arg":"mapperDemo.csproj"}, +{"typeStep":"text","arg":" This concludes the project"}, +{"typeStep":"waitseconds","arg":"30"}, +{"typeStep":"text","arg": "Remember, you can download the code from here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/Najlot.Map.SourceGenerator#download-example-net--c-", +SpeakTest=" "}, +{"typeStep":"waitseconds","arg":"30"}, +] +} diff --git a/v2/rscg_examples_site/docs/Authors/Najlot.md b/v2/rscg_examples_site/docs/Authors/Najlot.md index cc0c3d7a8..3022300ad 100644 --- a/v2/rscg_examples_site/docs/Authors/Najlot.md +++ b/v2/rscg_examples_site/docs/Authors/Najlot.md @@ -1,7 +1,9 @@ # Author : Najlot -Number RSCG: 1 +Number RSCG: 2 1 [Najlot.Audit.SourceGenerator](/docs/Najlot.Audit.SourceGenerator) [![Nuget](https://img.shields.io/nuget/dt/Najlot.Audit.SourceGenerator?label=Najlot.Audit.SourceGenerator)](https://www.nuget.org/packages/Najlot.Audit.SourceGenerator/) ![GitHub Repo stars](https://img.shields.io/github/stars/najlot/Audit?style=social) 2026-04-06 + 2 [Najlot.Map.SourceGenerator](/docs/Najlot.Map.SourceGenerator) [![Nuget](https://img.shields.io/nuget/dt/Najlot.Map.SourceGenerator?label=Najlot.Map.SourceGenerator)](https://www.nuget.org/packages/Najlot.Map.SourceGenerator/) ![GitHub Repo stars](https://img.shields.io/github/stars/najlot/Map?style=social) 2026-08-29 + diff --git a/v2/rscg_examples_site/docs/Categories/Mapper.md b/v2/rscg_examples_site/docs/Categories/Mapper.md index 1b7f8753b..0448fbc4e 100644 --- a/v2/rscg_examples_site/docs/Categories/Mapper.md +++ b/v2/rscg_examples_site/docs/Categories/Mapper.md @@ -1,6 +1,6 @@

Mapper

-Number RSCG: 10 +Number RSCG: 11 1 [AutoDTO](/docs/AutoDTO) [![Nuget](https://img.shields.io/nuget/dt/AutoDTO?label=AutoDTO)](https://www.nuget.org/packages/AutoDTO/) ![GitHub Repo stars](https://img.shields.io/github/stars/Ohorodnikov/AutoDto?style=social) 2023-08-24 @@ -20,5 +20,7 @@ Number RSCG: 10 9 [MapTo](/docs/MapTo) [![Nuget](https://img.shields.io/nuget/dt/MapTo?label=MapTo)](https://www.nuget.org/packages/MapTo/) ![GitHub Repo stars](https://img.shields.io/github/stars/mrtaikandi/MapTo?style=social) 2023-10-05 - 10 [NextGenMapper](/docs/NextGenMapper) [![Nuget](https://img.shields.io/nuget/dt/NextGenMapper?label=NextGenMapper)](https://www.nuget.org/packages/NextGenMapper/) ![GitHub Repo stars](https://img.shields.io/github/stars/DedAnton/NextGenMapper?style=social) 2023-08-16 + 10 [Najlot.Map.SourceGenerator](/docs/Najlot.Map.SourceGenerator) [![Nuget](https://img.shields.io/nuget/dt/Najlot.Map.SourceGenerator?label=Najlot.Map.SourceGenerator)](https://www.nuget.org/packages/Najlot.Map.SourceGenerator/) ![GitHub Repo stars](https://img.shields.io/github/stars/najlot/Map?style=social) 2026-08-29 + + 11 [NextGenMapper](/docs/NextGenMapper) [![Nuget](https://img.shields.io/nuget/dt/NextGenMapper?label=NextGenMapper)](https://www.nuget.org/packages/NextGenMapper/) ![GitHub Repo stars](https://img.shields.io/github/stars/DedAnton/NextGenMapper?style=social) 2023-08-16 \ No newline at end of file diff --git a/v2/rscg_examples_site/docs/Categories/_PrimitiveMapper.mdx b/v2/rscg_examples_site/docs/Categories/_PrimitiveMapper.mdx index 0839d498f..bfa8ca880 100644 --- a/v2/rscg_examples_site/docs/Categories/_PrimitiveMapper.mdx +++ b/v2/rscg_examples_site/docs/Categories/_PrimitiveMapper.mdx @@ -18,7 +18,9 @@ 9 [MapTo](/docs/MapTo) [![Nuget](https://img.shields.io/nuget/dt/MapTo?label=MapTo)](https://www.nuget.org/packages/MapTo/) ![GitHub Repo stars](https://img.shields.io/github/stars/mrtaikandi/MapTo?style=social) 2023-10-05 - 10 [NextGenMapper](/docs/NextGenMapper) [![Nuget](https://img.shields.io/nuget/dt/NextGenMapper?label=NextGenMapper)](https://www.nuget.org/packages/NextGenMapper/) ![GitHub Repo stars](https://img.shields.io/github/stars/DedAnton/NextGenMapper?style=social) 2023-08-16 + 10 [Najlot.Map.SourceGenerator](/docs/Najlot.Map.SourceGenerator) [![Nuget](https://img.shields.io/nuget/dt/Najlot.Map.SourceGenerator?label=Najlot.Map.SourceGenerator)](https://www.nuget.org/packages/Najlot.Map.SourceGenerator/) ![GitHub Repo stars](https://img.shields.io/github/stars/najlot/Map?style=social) 2026-08-29 + + 11 [NextGenMapper](/docs/NextGenMapper) [![Nuget](https://img.shields.io/nuget/dt/NextGenMapper?label=NextGenMapper)](https://www.nuget.org/packages/NextGenMapper/) ![GitHub Repo stars](https://img.shields.io/github/stars/DedAnton/NextGenMapper?style=social) 2023-08-16 ### See category diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/Najlot.Map.SourceGenerator.md b/v2/rscg_examples_site/docs/RSCG-Examples/Najlot.Map.SourceGenerator.md new file mode 100644 index 000000000..86ac45202 --- /dev/null +++ b/v2/rscg_examples_site/docs/RSCG-Examples/Najlot.Map.SourceGenerator.md @@ -0,0 +1,514 @@ +--- +sidebar_position: 2880 +title: 288 - Najlot.Map.SourceGenerator +description: Generates object mapping code at compile time using source generators +slug: /Najlot.Map.SourceGenerator +--- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import TOCInline from '@theme/TOCInline'; +import SameCategory from '../Categories/_PrimitiveMapper.mdx'; + +# Najlot.Map.SourceGenerator by Najlot + + + + +## NuGet / site data +[![Nuget](https://img.shields.io/nuget/dt/Najlot.Map.SourceGenerator?label=Najlot.Map.SourceGenerator)](https://www.nuget.org/packages/Najlot.Map.SourceGenerator/) +[![GitHub last commit](https://img.shields.io/github/last-commit/najlot/Map?label=updated)](https://github.com/najlot/Map) +![GitHub Repo stars](https://img.shields.io/github/stars/najlot/Map?style=social) + +## Details + +### Info +:::info + +Name: **Najlot.Map.SourceGenerator** + +Source generator for Najlot.Map that provides automatic mapping code generation with high performance caching. + +Author: Najlot + +NuGet: +*https://www.nuget.org/packages/Najlot.Map.SourceGenerator/* + + +You can find more details at https://github.com/najlot/Map + +Source: https://github.com/najlot/Map + +::: + +### Author +:::note +Najlot +![Alt text](https://github.com/najlot.png) +::: + +## Original Readme +:::note + +# ![M](https://github.com/najlot/Map/blob/main/images/icon.png) Najlot.Map + +Najlot.Map is a high-performance object mapping library for .NET built around explicit mapping methods. +Instead of convention-heavy auto-mapping, it keeps mapping logic in normal C# methods so behavior stays readable, predictable, and easy to review. +When you want less boilerplate, you can add the optional source generator and keep the same programming model. + +Najlot.Map is a good fit when you want: + +* explicit mappings instead of hidden conventions, +* strong runtime performance without magic in the hot path, +* a single `IMap` entry point for object, collection, async, and queryable mapping, +* the option to scale from handwritten methods to generated mappings. + +--- + +## Why Najlot.Map + +* Unlike convention-based mappers, mapping behavior lives in regular C# methods you can read, debug, and review directly. +* Unlike tools that rely on runtime magic, Najlot.Map keeps the hot path explicit and lets you add source generation only when it helps. +* Unlike broad auto-mapping defaults, it favors predictable registrations and validation so mapping changes are easier to catch in tests or startup checks. + +--- + +## What It Does + +* Explicit method-based mappings +* Central `IMap` container +* Object, collection, nullable, and async enumerable mapping +* `IQueryable` projections through expressions +* Optional Roslyn source generator +* Validation for delegate-based mappings in tests +* Factory-based object creation for DI or custom activation + +--- + +## Packages + +Najlot.Map is distributed as two NuGet packages: + +| Package | Description | +| --- | --- | +| `Najlot.Map` | Core runtime, attributes, registration, validation, and mapping APIs | +| `Najlot.Map.SourceGenerator` | Optional compile-time generation for mapping methods and registration | + +--- + +## Installation + +Install the runtime package: + +```bash +dotnet add package Najlot.Map +``` + +Add the source generator when you want compile-time generated mappings: + +```bash +dotnet add package Najlot.Map.SourceGenerator +``` + +--- + +## Core Model + +* Mappings are regular methods, not configuration files. +* `IMap` is the single entry point for registration and execution. +* Public mapping methods can be discovered and registered automatically. +* Generated mappings follow the same runtime API as handwritten mappings. +* Validation is meant for tests and startup checks, not the request path. + +--- + +## Quick Start + +### 1. Write mapping methods + +```csharp +using Najlot.Map; +using Najlot.Map.Attributes; + +internal class UserMappings +{ + [MapIgnoreProperty(nameof(User.Password))] + public void MapModelToUser(IMap map, UserModel from, User to) + { + to.Id = from.Id; + to.Username = from.Username; + to.Features = map + .From(from.Features) + .ToList(); + } + + [MapIgnoreProperty(nameof(UserModel.Password))] + public UserModel MapUserToModel(IMap map, User from) => new() + { + Id = from.Id, + Username = from.Username, + Features = map + .From(from.Features) + .To() + }; + + [MapIgnoreMethod] + public Guid IgnoredMethod(UserModel from) => from.Id; +} +``` + +### 2. Register the mappings + +```csharp +var map = new Map() + .Register(); +``` + +If your mapping classes need custom construction, register a factory: + +```csharp +var map = new Map() + .RegisterFactory(type => serviceProvider.GetRequiredService(type)) + .Register(); +``` + +### 3. Map objects and collections + +```csharp +var user = map.From(userModel).To(); +var users = map.From(userModels).To().ToList(); +``` + +--- + +## Registration Options + +### Manual registration + +Register a class and let Najlot.Map inspect its public methods: + +```csharp +var map = new Map() + .Register(); +``` + +Supported method shapes include: + +```csharp +void Map(TFrom from, TTo to) +void Map(IMap map, TFrom from, TTo to) +TTo Map(TFrom from) +TTo Map(IMap map, TFrom from) +Expression> Projection() +``` + +### Generated registration + +When using `Najlot.Map.SourceGenerator`, classes marked with `[Mapping]` get picked up and the generator emits an assembly-specific extension method named `Register{AssemblyName}Mappings()`. + +```csharp +var map = new Map() + .RegisterMyProjectMappings(); +``` + +If generated mapping classes need constructor injection, the same `RegisterFactory(...)` hook applies. + +--- + +## Source Generator + +The source generator keeps the same explicit programming model while removing repetitive mapping code. + +```csharp +using Najlot.Map; +using Najlot.Map.Attributes; + +[Mapping] +public partial class UserMappings +{ + public partial void MapUser(IMap map, UserModel from, User to); + public partial void MapFeature(IMap map, UserFeatureModel from, UserFeature to); + + public DateTime ConvertToUtc(DateTimeOffset offset) => offset.UtcDateTime; +} +``` + +Usage: + +```csharp +var map = new Map() + .RegisterMyProjectMappings(); + +var user = map.From(userModel).To(); +``` + +Use the generator when you want to reduce boilerplate but still keep mappings explicit, typed, and reviewable. + +--- + +## Validation + +`Validate()` checks registered delegate-based mappings and throws `MapMissPropertiesException` when destination properties are left unmapped and not explicitly ignored. + +```csharp +var map = new Map() + .Register(); + +map.Validate(); +``` + +Recommended usage: + +* unit tests, +* integration tests, +* application startup checks. + +Validation does not cover expression-based mappings used for `IQueryable` projections. + +--- + +## Queryable Projections + +For `IQueryable` scenarios such as Entity Framework Core, register an expression mapping so the provider can translate it. + +```csharp +using System.Linq.Expressions; +using Najlot.Map.Attributes; + +[Mapping] +public partial class UserMappings +{ + public static partial Expression> ToListItem(); +} +``` + +Usage: + +```csharp +var map = new Map() + .RegisterMyProjectMappings(); + +var query = map.From(db.Users).To(); +var items = await query.ToListAsync(); +``` + +Use delegate mappings for in-memory object graphs. +Use expression mappings when the projection needs to stay provider-translatable. + +--- + +## Design Principles + +Najlot.Map is intentionally not a convention-over-configuration auto-mapper. +Its value is in making mappings obvious and controllable while still giving you enough tooling to keep the codebase fast and maintainable as it grows. + +That means: + +* explicit code over implicit behavior, +* predictable runtime behavior over hidden fallback rules, +* optional generation over mandatory framework ceremony. + +--- + +## License + +MIT License + +::: + +### About +:::note + + Generates object mapping code at compile time using source generators + + +::: + +## How to use + +### Example (source csproj, source files) + + + + + +This is the CSharp Project that references **Najlot.Map.SourceGenerator** +```xml showLineNumbers {17} + + + + Exe + net10.0 + enable + enable + + + + true + $(BaseIntermediateOutputPath)\GX + + + + + + + + + + + + + + +``` + + + + + + This is the use of **Najlot.Map.SourceGenerator** in *Program.cs* + +```csharp showLineNumbers +using mapperDemo; +using Najlot.Map; +var map = new Map(); +map.RegistermapperDemoMappings(); +map.Validate(); +var p=new Person(); +p.FirstName = "Andrei"; +p.LastName = "Ignat"; +PersonDTO personDTO=map.From(p).To(); +Console.WriteLine(personDTO.FullName); + +``` + + + + + This is the use of **Najlot.Map.SourceGenerator** in *Person.cs* + +```csharp showLineNumbers + +public partial class Person +{ + public int ID \{ get; set; } + public string? FirstName \{ get; set; } + public string? LastName \{ get; set; } +} + + +``` + + + + + This is the use of **Najlot.Map.SourceGenerator** in *PersonDTO.cs* + +```csharp showLineNumbers +using Najlot.Map; +using Najlot.Map.Attributes; +namespace mapperDemo; +public partial struct PersonDTO +{ + public string? FirstName \{ get; set; } + public string? LastName \{ get; set; } + + public string FullName \{ + get + { + return FirstName + " " + LastName; + } + } +} + + +[Mapping] +public partial class UserMapper +{ + [MapIgnoreProperty(nameof(Person.ID))] + public partial PersonDTO MapUser(Person from); +} +``` + + + + +### Generated Files + +Those are taken from $(BaseIntermediateOutputPath)\GX + + + + +```csharp showLineNumbers +// +#nullable enable + +namespace mapperDemo +{ + partial class UserMapper + { + public partial mapperDemo.PersonDTO MapUser(Person from) + { + var result = new mapperDemo.PersonDTO(); + + result.FirstName = from.FirstName; + result.LastName = from.LastName; + + return result; + } + + } +} + +``` + + + + +```csharp showLineNumbers +// +#nullable enable +using Najlot.Map; + +namespace mapperDemo +{ + public static class MapRegistrationExtensions_mapperDemo + { + public static IMap RegistermapperDemoMappings(this IMap map) + { + var instance_mapperDemo_UserMapper = map.Create(); + map.Register(instance_mapperDemo_UserMapper.MapUser); + return map; + } + } +} + +``` + + + + +## Useful + +### Download Example (.NET C#) + +:::tip + +[Download Example project Najlot.Map.SourceGenerator ](/sources/Najlot.Map.SourceGenerator.zip) + +::: + + +### Share Najlot.Map.SourceGenerator + + + +https://ignatandrei.github.io/RSCG_Examples/v2/docs/Najlot.Map.SourceGenerator + + + diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/index.md b/v2/rscg_examples_site/docs/RSCG-Examples/index.md index f996a8660..def3a6862 100644 --- a/v2/rscg_examples_site/docs/RSCG-Examples/index.md +++ b/v2/rscg_examples_site/docs/RSCG-Examples/index.md @@ -1,7 +1,7 @@ --- sidebar_position: 30 -title: 287 RSCG list by category -description: 287 RSCG list by category +title: 288 RSCG list by category +description: 288 RSCG list by category slug: /rscg-examples --- @@ -1310,7 +1310,7 @@ import DocCardList from '@theme/DocCardList'; ## Mapper
- Expand Mapper =>examples:10 + Expand Mapper =>examples:11 @@ -1361,6 +1361,11 @@ import DocCardList from '@theme/DocCardList'; [lomapper](/docs/lomapper) + + + +[Najlot.Map.SourceGenerator](/docs/Najlot.Map.SourceGenerator) +
@@ -2238,6 +2243,8 @@ flowchart LR; Mapper--> lomapper((lomapper)) + Mapper--> Najlot.Map.SourceGenerator((Najlot.Map.SourceGenerator)) + MCP--> RSCG_MCP2OpenAPI((RSCG_MCP2OpenAPI)) MCP--> RSCG_MCP2File((RSCG_MCP2File)) diff --git a/v2/rscg_examples_site/docs/about.md b/v2/rscg_examples_site/docs/about.md index d3d8fbc0e..f59601273 100644 --- a/v2/rscg_examples_site/docs/about.md +++ b/v2/rscg_examples_site/docs/about.md @@ -6,7 +6,7 @@ title: About ## Content You will find here code examples -of 287 Roslyn Source Code Generator (RSCG) +of 288 Roslyn Source Code Generator (RSCG) that can be useful for you. That means, you will write more elegant and concise code - even if the generators code is not always nice to look. ## Are those examples ready for production? diff --git a/v2/rscg_examples_site/docs/indexRSCG.md b/v2/rscg_examples_site/docs/indexRSCG.md index c338f5100..b47e677d6 100644 --- a/v2/rscg_examples_site/docs/indexRSCG.md +++ b/v2/rscg_examples_site/docs/indexRSCG.md @@ -7,9 +7,9 @@ slug: /List-of-RSCG import useBaseUrl from '@docusaurus/useBaseUrl'; -## 287 RSCG with examples in descending chronological order +## 288 RSCG with examples in descending chronological order -This is the list of 287 ( 16 from Microsoft) RSCG with examples +This is the list of 288 ( 16 from Microsoft) RSCG with examples [See by category](/docs/rscg-examples) [See as json](/exports/RSCG.json) [See as Excel](/exports/RSCG.xlsx) @@ -20,6 +20,7 @@ This is the list of 287 ( 16 from Microsoft) RSCG with examples | No | Name | Date | Category | | --------- | ----- | ---- | -------- | +|288| [Najlot.Map.SourceGenerator by Najlot ](/docs/Najlot.Map.SourceGenerator)|2026-08-29 => 29 August 2026 | [Mapper](/docs/Categories/Mapper) | |287| [TrimItEasy by Phong Nguyen ](/docs/TrimItEasy)|2026-08-28 => 28 August 2026 | [EnhancementClass](/docs/Categories/EnhancementClass) | |286| [SatorImaging.TDoubles by Sator Imaging ](/docs/SatorImaging.TDoubles)|2026-08-27 => 27 August 2026 | [Tests](/docs/Categories/Tests) | |285| [PropertyResolvers by Tom Biddulph ](/docs/PropertyResolvers)|2026-08-26 => 26 August 2026 | [EnhancementProject](/docs/Categories/EnhancementProject) | diff --git a/v2/rscg_examples_site/src/components/HomepageFeatures/index.js b/v2/rscg_examples_site/src/components/HomepageFeatures/index.js index 756d9e805..d1d973ce6 100644 --- a/v2/rscg_examples_site/src/components/HomepageFeatures/index.js +++ b/v2/rscg_examples_site/src/components/HomepageFeatures/index.js @@ -4,7 +4,7 @@ import styles from './styles.module.css'; const FeatureList = [ { -title: '287 Examples (16 from MSFT)', +title: '288 Examples (16 from MSFT)', Svg: require('@site/static/img/undraw_docusaurus_mountain.svg').default, description: ( <> diff --git a/v2/rscg_examples_site/static/exports/RSCG.json b/v2/rscg_examples_site/static/exports/RSCG.json index fc7520304..807b91ebe 100644 --- a/v2/rscg_examples_site/static/exports/RSCG.json +++ b/v2/rscg_examples_site/static/exports/RSCG.json @@ -2297,6 +2297,14 @@ "Source": "https://github.com/phongnguyend/TrimItEasy", "Category": "EnhancementClass", "AddedOn": "2026-08-28T00:00:00" + }, + { + "Name": "Najlot.Map.SourceGenerator", + "Link": "https://ignatandrei.github.io/RSCG_Examples/v2/docs/Najlot.Map.SourceGenerator", + "NuGet": "https://www.nuget.org/packages/Najlot.Map.SourceGenerator/", + "Source": "https://github.com/najlot/Map", + "Category": "Mapper", + "AddedOn": "2026-08-29T00:00:00" } ] } \ No newline at end of file diff --git a/v2/rscg_examples_site/static/exports/RSCG.xlsx b/v2/rscg_examples_site/static/exports/RSCG.xlsx index e22a771f3a21cd4791d4be8a41f4f05e948c524a..237850b1f7e185e396da70938668ec1470fb20a4 100644 GIT binary patch delta 813 zcmeAx-B?;5;LXe;!oa}5!Js}zDK@Yw;MravPl=I%fgea$HV=4^^M@Nmb?#tOCHTCW;D%UP+}JP(rJB= z&Dm)uW$wxSljmQRy|~c(SJK7S=^e-YT5rsZzHH19`RtRr=*P?3_b{V+^;CSrr+JJU z|Ltew1Nq!9c!AzxBL;>WdYex(6&ociR+X;)S$NTqIjGiiyZFI}#kXRfh-$<|cQ^d~ zI{8lSezpbMW{NS#e>QwRA$;+Sx^OlpogIG)EdS{~c2=l-{yq5Yulu*2p3h?4`sZi; ze|RV}fJ1rS>j^J5*O*E(3M83YnkSnWrlce#TAG*}n@(PCCdUbKjx68m^S39TGgGhk z&0{j;aRY|<{f{j^%Nsayb|rT2aNw9HZ#dbdQ?p>3Ue%Jgg_)tDJy%@KV8C_~M=#hfP<#2yw0V1N`=9&}H&ENh zJH_FRZ%(J_gVG=8y3R0dw9UG4mXCYolu2IKLPGtySpLnvaP)ZatB#6SUxd@2o>zMR z#Ut$0iCcOqva2e8{#e>RS$&N?14?{szGbe($N@`(lX)ynnSq?iE|wN((KETr(n21j z4it(Sz;p`2+`zPo06mi*T1tV{fP)bzu@|UD3ZVeVx;t6QN)xQ+rr!LAzknhUObiUd RC~7`TPO?&ClePp20s!}RN$mgt delta 777 zcmdm3+E-d1;LXe;!oa}5!N9*oG4@$ceDz)+Pl=I%fgea$ zwCSpix8OawfAaj7Ze7{2^jFfw*6AI`<63Xbj5aplh!p*#F8cBE_Fc@VUOg4x@M#|7 z#((=6`2>JI=V1Quq0xwe;ji}Q(@e!icC$UrKA6fE^PObxdRd;jAgnQ-#k}LbksXU( zd7b^$C;!&Q{#!F`=BfGrzyD{48O*={GRa|Ob@=9arqYZ8DQ0G724;q4CYFYVCMo7g zlTVt-ae|bjPZZmDYw`y(^?Gl=!v+El>yysTyTO@R7;rc5#)h?3jK^iw1BGvIT7F^P zTJF9hq6VR@Qk|^QVT*s-?!8zOXBRg6vdJd%p3Dz^j*%P*FM96tuL~|v`K^$+IWD*G z$`th=`<5f0y1con7JWEVX=LkXC2F_ewCwB0OEi~neC#;8`Q3zYC!NYY=?CVdoh*Ca zP_I~(&EBkkPe#4u3-=6ltNs}cZ%f`x5czPqVzuZ@);Fc=6LznW);zVXc1p%;^~wFu z{;Pd?_gL|3he`P_&Ge`51Ma=tY8vL7DeiQ7*)-9(uRq>!zSf6@2?r=lHvcu(V&s4& zu*v$Crp!Rj Date: Wed, 2 Sep 2026 19:35:48 +0300 Subject: [PATCH 2/2] zip --- v2/RSCGExamplesData/GeneratorDataRec.json | 3 +- .../examples/Najlot.Map.SourceGenerator.html | 70 ++++++++++++++++++ v2/book/list.html | 6 +- v2/book/pandocHTML.yaml | 1 + v2/docFind.json | 6 ++ .../Najlot.Map.SourceGenerator.md | 36 ++++----- .../static/exports/RSCG.xlsx | Bin 15025 -> 15027 bytes .../sources/Najlot.Map.SourceGenerator.zip | Bin 0 -> 1491 bytes 8 files changed, 101 insertions(+), 21 deletions(-) create mode 100644 v2/book/examples/Najlot.Map.SourceGenerator.html create mode 100644 v2/rscg_examples_site/static/sources/Najlot.Map.SourceGenerator.zip diff --git a/v2/RSCGExamplesData/GeneratorDataRec.json b/v2/RSCGExamplesData/GeneratorDataRec.json index a7cce867e..9ad5baeba 100644 --- a/v2/RSCGExamplesData/GeneratorDataRec.json +++ b/v2/RSCGExamplesData/GeneratorDataRec.json @@ -1740,8 +1740,7 @@ "dtStart": "2026-08-28T00:00:00", "show": true } - , - { + ,{ "ID":"Najlot.Map.SourceGenerator", "Category": 6, "dtStart": "2026-08-29T00:00:00", diff --git a/v2/book/examples/Najlot.Map.SourceGenerator.html b/v2/book/examples/Najlot.Map.SourceGenerator.html new file mode 100644 index 000000000..e61d16cbb --- /dev/null +++ b/v2/book/examples/Najlot.Map.SourceGenerator.html @@ -0,0 +1,70 @@ + +

RSCG nr 288 : Najlot.Map.SourceGenerator

+ +

Info

+Nuget : https://www.nuget.org/packages/Najlot.Map.SourceGenerator/ + +

You can find more details at : https://github.com/najlot/Map

+ +

Author :Najlot

+ +

Source: https://github.com/najlot/Map

+ +

About

+ + Generates object mapping code at compile time using source generators + +

+ How to use +

+

+ Add reference to the Najlot.Map.SourceGenerator in the csproj +

+ + +

This was for me the starting code

+ +
+ I have coded the file Program.cs +
+ +
+ +
+ I have coded the file Person.cs +
+ +
+ +
+ I have coded the file PersonDTO.cs +
+ +
+

And here are the generated files

+ +
+ The file generated is mapperDemo_UserMapper.g.cs +
+ + +
+ The file generated is MapRegistrationExtensions_mapperDemo.g.cs +
+ + +

+ You can download the code and this page as pdf from + + https://ignatandrei.github.io/RSCG_Examples/v2/docs/Najlot.Map.SourceGenerator + +

+ + +

+ You can see the whole list at + + https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG + +

+ diff --git a/v2/book/list.html b/v2/book/list.html index d9219e0a0..b03855ea7 100644 --- a/v2/book/list.html +++ b/v2/book/list.html @@ -17,7 +17,7 @@

-This is the list of 287 RSCG with examples => +This is the list of 288 RSCG with examples =>

@@ -1174,6 +1174,10 @@

+ + + +
287 TrimItEasy
288Najlot.Map.SourceGenerator
diff --git a/v2/book/pandocHTML.yaml b/v2/book/pandocHTML.yaml index 9cfa09947..261b8b8bf 100644 --- a/v2/book/pandocHTML.yaml +++ b/v2/book/pandocHTML.yaml @@ -301,6 +301,7 @@ input-files: - examples/PropertyResolvers.html - examples/SatorImaging.TDoubles.html - examples/TrimItEasy.html +- examples/Najlot.Map.SourceGenerator.html # or you may use input-file: with a single value # defaults: diff --git a/v2/docFind.json b/v2/docFind.json index 15638d3e5..143083338 100644 --- a/v2/docFind.json +++ b/v2/docFind.json @@ -1720,5 +1720,11 @@ "category": "EnhancementClass", "href": "/RSCG_Examples/v2/docs/TrimItEasy/", "body": "Package Description" + }, + { + "title": "Najlot.Map.SourceGenerator", + "category": "Mapper", + "href": "/RSCG_Examples/v2/docs/Najlot.Map.SourceGenerator/", + "body": "Source generator for Najlot.Map that provides automatic mapping code generation with high performance caching." } ] \ No newline at end of file diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/Najlot.Map.SourceGenerator.md b/v2/rscg_examples_site/docs/RSCG-Examples/Najlot.Map.SourceGenerator.md index 86ac45202..3e1cad3f1 100644 --- a/v2/rscg_examples_site/docs/RSCG-Examples/Najlot.Map.SourceGenerator.md +++ b/v2/rscg_examples_site/docs/RSCG-Examples/Najlot.Map.SourceGenerator.md @@ -49,7 +49,7 @@ Najlot ## Original Readme :::note -# ![M](https://github.com/najlot/Map/blob/main/images/icon.png) Najlot.Map +### ![M](https://github.com/najlot/Map/blob/main/images/icon.png) Najlot.Map Najlot.Map is a high-performance object mapping library for .NET built around explicit mapping methods. Instead of convention-heavy auto-mapping, it keeps mapping logic in normal C# methods so behavior stays readable, predictable, and easy to review. @@ -64,7 +64,7 @@ Najlot.Map is a good fit when you want: --- -## Why Najlot.Map +###### Why Najlot.Map * Unlike convention-based mappers, mapping behavior lives in regular C# methods you can read, debug, and review directly. * Unlike tools that rely on runtime magic, Najlot.Map keeps the hot path explicit and lets you add source generation only when it helps. @@ -72,7 +72,7 @@ Najlot.Map is a good fit when you want: --- -## What It Does +###### What It Does * Explicit method-based mappings * Central `IMap` container @@ -84,7 +84,7 @@ Najlot.Map is a good fit when you want: --- -## Packages +###### Packages Najlot.Map is distributed as two NuGet packages: @@ -95,7 +95,7 @@ Najlot.Map is distributed as two NuGet packages: --- -## Installation +###### Installation Install the runtime package: @@ -111,7 +111,7 @@ dotnet add package Najlot.Map.SourceGenerator --- -## Core Model +###### Core Model * Mappings are regular methods, not configuration files. * `IMap` is the single entry point for registration and execution. @@ -121,9 +121,9 @@ dotnet add package Najlot.Map.SourceGenerator --- -## Quick Start +###### Quick Start -### 1. Write mapping methods +######### 1. Write mapping methods ```csharp using Najlot.Map; @@ -156,7 +156,7 @@ internal class UserMappings } ``` -### 2. Register the mappings +######### 2. Register the mappings ```csharp var map = new Map() @@ -171,7 +171,7 @@ var map = new Map() .Register(); ``` -### 3. Map objects and collections +######### 3. Map objects and collections ```csharp var user = map.From(userModel).To(); @@ -180,9 +180,9 @@ var users = map.From(userModels).To().ToList(); --- -## Registration Options +###### Registration Options -### Manual registration +######### Manual registration Register a class and let Najlot.Map inspect its public methods: @@ -201,7 +201,7 @@ TTo Map(IMap map, TFrom from) Expression> Projection() ``` -### Generated registration +######### Generated registration When using `Najlot.Map.SourceGenerator`, classes marked with `[Mapping]` get picked up and the generator emits an assembly-specific extension method named `Register{AssemblyName}Mappings()`. @@ -214,7 +214,7 @@ If generated mapping classes need constructor injection, the same `RegisterFacto --- -## Source Generator +###### Source Generator The source generator keeps the same explicit programming model while removing repetitive mapping code. @@ -245,7 +245,7 @@ Use the generator when you want to reduce boilerplate but still keep mappings ex --- -## Validation +###### Validation `Validate()` checks registered delegate-based mappings and throws `MapMissPropertiesException` when destination properties are left unmapped and not explicitly ignored. @@ -266,7 +266,7 @@ Validation does not cover expression-based mappings used for `IQueryable` pro --- -## Queryable Projections +###### Queryable Projections For `IQueryable` scenarios such as Entity Framework Core, register an expression mapping so the provider can translate it. @@ -296,7 +296,7 @@ Use expression mappings when the projection needs to stay provider-translatable. --- -## Design Principles +###### Design Principles Najlot.Map is intentionally not a convention-over-configuration auto-mapper. Its value is in making mappings obvious and controllable while still giving you enough tooling to keep the codebase fast and maintainable as it grows. @@ -309,7 +309,7 @@ That means: --- -## License +###### License MIT License diff --git a/v2/rscg_examples_site/static/exports/RSCG.xlsx b/v2/rscg_examples_site/static/exports/RSCG.xlsx index 237850b1f7e185e396da70938668ec1470fb20a4..95d651dc18e6a63f8ca42adab3980c5e4dd0e4b3 100644 GIT binary patch delta 750 zcmdm3y1BGIz?+#xgn@y9gCT#8QtZCO*gXe;JS9d327Vx2k)vOpUzDAcpP#K)k(<-o ze>$((K)|*B=&ag}v(*G$9mIM=QfJpSZe-tZK<1;<_u_Jfep4XaH zb3aM2pY(Rgt#t9Jn`XVV?^3q-gU|PEpT-M0R_8qU_3abaqj@no*BAx0r$4N!sM{1< zY2d#4O5JkZn(8C}D+2CYH>Vq|K0aZei_$r(r{`>TwK|^IHmyELvi{dLc~sw?if`EX z`w$~z{^os5H;gzy0bo_IE@<;SQyE5nb5jfBl+;wSL^CrJLre3?C(YzIK`Pz^ZcDp0 z`Gc8y{XxIO20U%?s-NbnMQ>lZAa!@aL#wx}caCJP-s&lmzQIGj&%gaQRqCj*s$A3c4J$-AKB?U}ST1$$=3Ubb_jCD8lJunS@K1EL{J3V} zc}qKwlgpNK?&O+SGjqoTwKGe7=k{dy-Iy4owRPglX^h1w%PiuQ|F%lZk>;^wE1q}a zdHjJ%pG#HP3Xfa~yr!W4xI9c$tV4bE!vzyWq*9}=Ut4|bio%oqoO@eJ9?jD@Kez7D zqCb&h=2fqM-`aNeR?eEB)vCAjZ7r)0y<NjOzh%ZXbDc08mktl}1VgaaZFHoZtipB?%ZLKsJ^CzcU$ufSL+-jx9CTj^& F007)EAX)$b delta 732 zcmdm7y0NrAz?+#xgn@y9gF$_cQfy#Vz_YzTo)RMi13!?i$k8v)FUn5J&(GGY$j#~P z_vAZdz~j1JsFFW(CQE3vn1bTAf~E<(a$SVO3mfF-8|2@#t&hI;`)AdLxjPo6JFjaf znbY8~e5KJk%?CoSE(%>swM#Mo^j!F2z(F%p4{cSy28hH*N)XEqeUOR zkUqKBJ+!b}B1c`_bJK({N%sEw^HcV#%-Ixi;Ngy&jTLIYwO%!RnAurypu{ZnrPKN# zo3qnS%G{ItC(pksdvT%nucV8u(>sp)wceN+ec6~J^4TYK(T|t6?_oyu>Z$mKPxBZz zGcxXHWK`dLkm-gI2Pg#Qy`J!5^FmV@Mt)OE^JEjll$4}IOA~Wr)5&MdSu@;iFL zeu3J{U#895Yuo?ihq!^-KHez~Z+vq)O&^s0IM;QCX`^k{jkA2*E2m8Ix)u`Z&&Bd@ z_JyOzgI{%2y!s-X{`9=k`!610r%v3`Q;}U&`SZup_Q~pN>=}?kZS!Aq9Y#)gI+<)_ zX~L*JIo(oL?iD1h6qi)yq!xoxN`N;blL!MeVNE{BB+Ly|0R@{UAFx!12lnLmmSR>t urVI@6MX5Q(`g$M|MK?x}!^{EEcPHChX#yRQX(h|}VRE~b8k@8wNE`sH#33R8 diff --git a/v2/rscg_examples_site/static/sources/Najlot.Map.SourceGenerator.zip b/v2/rscg_examples_site/static/sources/Najlot.Map.SourceGenerator.zip new file mode 100644 index 0000000000000000000000000000000000000000..290c28fdeaf802b6b1b695c5572414c6d16ac344 GIT binary patch literal 1491 zcmWIWW@Zs#U|`^2@L1FyW7)hb$QsD=0b+h2&P^;RNG)S%cA7I~gMd)?jO>!fb(hE-EUzBESVe3|%# znIQmf&*@o8vF2~@H0U!jFtjr{v%lh8fns<9oZSSXCxj!oP2la9$C}jD}Qky%|FYVW_kKg9`UtH%9 zWTSokZ^{~#TetK&eA$Y{7POQv&J#J_dxr5+TFW)-dk&0yK0dKIYtHxMf#|0%5AJ9^ zW18;ZEF!umBBq%6%ISz{%a6OP*4J7-HKZh5d-EDgiH}Q~KMLOIQjdGxcK`IZ17<~4 zb9PFX?)&TA`)U;Vdp(rmpl7DxR#sO$4qA&TKv?)Gh|v--t%_#*;(=WM0eTYL1( zqksXt2#7(^j0j!*fYhSm{5-wn;_Cg?_WI$DnL&POo17ez0zK1``kadVk_tCEIb;PE z*2(FIo9a(z5^%Vh@@%R`#V(By?Ip{nMQDpOcSMP>9#wUnS^4rCSKdt5qpEeCJ6F1_ z`09CNok&N;PNYcR4s=VE^AVk|KsVd~M!YySx44A(1D%r_;GK2YK;W))P5Z*tGaB?C zxN6RDSnyM4Qs_x1!>+)Is)oi9-oKw0B3xPAFYVa5)AZK_uWM^RulW9g^}%-6 zqHFPD<>yb8#)>SDkN_Y=ZM`pJH|n~W2wRwt)LRy3kzL78LO<6JJ;&|iAzm$ z+wO<6-|ziiTkod+<$#F5!nFZ2&sLc(6qCDDQOCsfg44`uO^Q^!&W1f4CIWRw9WDCH zGCAV8So6a26kPe`ggbmgj!ol^N-t?TlASm=-!XBT| z7yoNL4$AF4werE-o99mH>B{t!xhd_Bez;Lk>a*p^*MX-j1oz4Zcr!AIfRiEi(gx^L zB!Eb&;IaoL}@Z+mPZgKT?B?dl1cC!gKPq}l#MVU7FfVxm;g!V i$cA8xbc7-8%&3OIlR$tsD;r1|D-Z?(-I~J!;sF3ssWQC) literal 0 HcmV?d00001