Incursa.Generators by Incursa
NuGet / site data
Details
Info
Name: Incursa.Generators
Roslyn source generators for strongly typed identifiers, enums, DTOs, and value objects from JSON or XML definitions.
Author: Incursa
NuGet: https://www.nuget.org/packages/Incursa.Generators/
You can find more details at https://github.com/incursa/generators
Author
Incursa

Original Readme
Incursa.Generators
Incursa.Generators generates strongly typed domain models from JSON and XML definition files. This example defines a Person DTO in Person.dto.json with required FirstName and LastName properties.
The generated Person.Create factory validates the new record before returning it. The demo creates a person and prints the full name. DTO/entity definitions use FluentValidation, so the project references that package directly.
See the Incursa.Generators repository for the full documentation and supported definition formats.
About
Generating strongly typed DTO and entity models from JSON or XML definitions
How to use
Example (source csproj, source files)
- CSharp Project
- Program.cs
This is the CSharp Project that references Incursa.Generators
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Incursa.Generators" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>analyzers;build;buildTransitive;contentFiles</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentValidation" Version="12.2.0" />
</ItemGroup>
</Project>
This is the use of Incursa.Generators in Program.cs
using Incursa.Generators.Demo;
var person = Person.Create("Ignat", "Andrei");
Console.WriteLine($"{person.FirstName} {person.LastName}");
Generated Files
Those are taken from $(BaseIntermediateOutputPath)\GX
- Incursa.Generators.Demo.Person.g.cs
- Person.dto.json
// <auto-generated/>
#nullable enable
namespace Incursa.Generators.Demo;
using System;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using FluentValidation;
public partial record Person
{
/// <summary>
/// Gets the FirstName property.
/// </summary>
[Required]
public required string FirstName \{ get; init; }
/// <summary>
/// Gets the LastName property.
/// </summary>
[Required]
public required string LastName \{ get; init; }
// Private constructor to enforce strict DTO pattern
private Person() \{ }
/// <summary>
/// Factory method to create a validated instance of Person.
/// </summary>
public static Person Create(
string firstName,
string lastName)
{
var instance = new Person
{
FirstName = firstName,
LastName = lastName
};
instance.Validate();
return instance;
}
// Static validator instance
public static readonly PersonValidator Validator = new PersonValidator();
// Instance method for validation
public void Validate()
{
var validationResult = Validator.Validate(this);
if (!validationResult.IsValid)
{
throw new FluentValidation.ValidationException(validationResult.ToString());
}
}
// Method to check validation without throwing exceptions
public FluentValidation.Results.ValidationResult GetValidationResult()
{
return Validator.Validate(this);
}
/// <summary>
/// Internal FluentValidator class for validation rules.
/// </summary>
public partial class PersonValidator : AbstractValidator<Person>
{
public PersonValidator() : base()
{
RuleFor(x => x.FirstName).NotNull().WithMessage("'{FirstName}' is required.");
RuleFor(x => x.LastName).NotNull().WithMessage("'{LastName}' is required.");
// Hooks for additional validation
AddCustomValidation();
}
// Partial method for additional validation hooks
partial void AddCustomValidation();
}
}
{
"name": "Person",
"namespace": "Incursa.Generators.Demo",
"strict": true,
"properties": [
{
"name": "FirstName",
"type": "string",
"required": true
},
{
"name": "LastName",
"type": "string",
"required": true
}
]
}
Useful
Download Example (.NET C#)
Share Incursa.Generators
https://ignatandrei.github.io/RSCG_Examples/v2/docs/Incursa.Generators
Category "EnhancementClass" has the following generators:
1 AOP.Logging.SourceGenerator
2026-08-30
2 ApparatusAOT
2023-04-16
3 AspectGenerator
2024-01-07
4 CommonCodeGenerator
2024-04-03
5 Comparison
2025-05-25
6 DudNet
2023-10-27
7 Enhanced.GetTypes
2024-09-17
8 FastGenericNew
2023-08-10
9 Immutype
2023-08-12
10 Incursa.Generators
2026-11-22
11 Ling.Audit
2023-12-12
12 Lombok.NET
2023-04-16
13 M31.FluentAPI
2023-08-25
14 MemberAccessor
2025-03-24
15 MemoryPack
2023-08-04
16 Meziantou.Polyfill
2023-10-10
17 Microsoft.Extensions.Logging
2023-04-16
18 Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator
2023-11-17
19 Microsoft.Interop.JavaScript.JSImportGenerator 2023-04-16
20 NLog.Extensions.ThisClass
2026-04-03
21 OptionToStringGenerator
2024-02-15
22 Pekspro.DataAnnotationValuesExtractor
2026-02-15
23 Program
2025-11-06
24 QueryStringGenerator
2024-11-07
25 RSCG_Decorator
2023-09-30
26 RSCG_UtilityTypes
2023-12-22
27 StaticReflection
2023-10-13
28 SyncMethodGenerator
2023-08-14
29 System.Runtime.InteropServices
2023-04-16
30 System.Text.RegularExpressions
2023-04-16
31 TelemetryLogging
2023-11-30
32 Tenekon.MethodOverloads.SourceGenerator
2026-09-05
33 ThisClass
2024-04-19
34 TrimItEasy
2026-08-28
35 VoloGen
2026-11-19