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..9ad5baeba 100644 --- a/v2/RSCGExamplesData/GeneratorDataRec.json +++ b/v2/RSCGExamplesData/GeneratorDataRec.json @@ -1740,5 +1740,11 @@ "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/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/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..3e1cad3f1 --- /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 e22a771f3..95d651dc1 100644 Binary files a/v2/rscg_examples_site/static/exports/RSCG.xlsx and b/v2/rscg_examples_site/static/exports/RSCG.xlsx differ 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 000000000..290c28fde Binary files /dev/null and b/v2/rscg_examples_site/static/sources/Najlot.Map.SourceGenerator.zip differ