Gener8 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Gener8 --version 0.1.0
                    
NuGet\Install-Package Gener8 -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Gener8" Version="0.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Gener8" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Gener8">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Gener8 --version 0.1.0
                    
#r "nuget: Gener8, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Gener8@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Gener8&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Gener8&version=0.1.0
                    
Install as a Cake Tool

Gener8

A C# Roslyn source generator that copies public properties from a model class into a decorated partial DTO class at compile time — no reflection, no runtime overhead.

NuGet CI

Installation

dotnet add package Gener8

The package is a development dependency — it is automatically marked PrivateAssets=all and adds no runtime reference to your project.

Quick start

// Your existing model
public class Product
{
    public required string Name { get; set; }
    public string Description { get; set; } = "";
    public decimal Price { get; set; }
    public bool InStock { get; set; }
}

// Your DTO — just add the attribute and make it partial
[FromModel(typeof(Product))]
internal partial class ProductDto { }

The generator emits at build time:

// <auto-generated/>
#nullable enable

internal partial class ProductDto
{
    public required string Name { get; set; }
    public string Description { get; set; } = "";
    public decimal Price { get; set; }
    public bool InStock { get; set; }
}

All accessor kinds (get, set, init), the required modifier, and property initializers are preserved exactly as declared on the source model.

Features

Feature Attribute / Parameter
Exclude specific properties Ignore = [nameof(Model.Prop)]
Map a nested type to a DTO type [TypeMapping(typeof(Address), typeof(AddressDto))]
Include properties from base classes IncludeInherited = true
Inline (flatten) a nested object Flatten = [nameof(Model.Prop)]
Rename a property in the output [RenameProperty("OldName", "NewName")]
Mapping extension methods Generated automatically alongside every DTO
Generate a repository scaffold Repository = RepositoryType.DynamoDb, RepositoryType.MongoDb, or RepositoryType.Custom

See docs/features.md for detailed examples of every feature.

Examples

Ignore properties

[FromModel(typeof(Product), Ignore = [nameof(Product.InternalCode)])]
internal partial class ProductDto { }

Type mapping

[FromModel(typeof(Order))]
[TypeMapping(typeof(Address), typeof(AddressDto))]
internal partial class OrderDto { }

Include inherited properties

[FromModel(typeof(DerivedProduct), IncludeInherited = true)]
internal partial class DerivedProductDto { }

Flatten a nested object

// Address { Street, City, PostCode }
[FromModel(typeof(Order), Flatten = [nameof(Order.ShippingAddress)])]
internal partial class OrderDto { }
// Emits: ShippingAddressStreet, ShippingAddressCity, ShippingAddressPostCode

Rename a property

[FromModel(typeof(Product))]
[RenameProperty(nameof(Product.InternalSku), "Sku")]
internal partial class ProductDto { }

Mapping extension methods

Every [FromModel] DTO automatically gets a companion extensions class with ToModel and ToDto methods:

[FromModel(typeof(Product))]
internal partial class ProductDto { }

// Generated automatically:
// internal static class ProductDtoExtensions
// {
//     public static Product    ToModel(this ProductDto dto)    { ... }
//     public static ProductDto ToDto  (this Product    model)  { ... }
// }

// Usage:
ProductDto dto = product.ToDto();
Product    model = dto.ToModel();

Type-mapped properties generate chained calls — dto.ShippingAddress.ToModel() and model.ShippingAddress.ToDto().

Repository scaffold

Set Repository to generate a concrete repository class that inherits from the SDK-specific abstract base provided by Gener8:

[FromModel(typeof(Product), Repository = RepositoryType.DynamoDb)]
internal partial class ProductDto { }

// Generates ProductDtoRepository.g.cs:
// internal partial class ProductDtoRepository : Gener8.DynamoDbRepository<Product, ProductDto>
// {
//     public ProductDtoRepository(IDynamoDbRepositoryContext context) : base(context) {}
//     protected override Product    ToModel(ProductDto dto)   => dto.ToModel();
//     protected override ProductDto ToDto  (Product    model) => model.ToDto();
// }

Use RepositoryType.MongoDb for a MongoDB variant — it receives an IMongoDbRepositoryContext and sets the collection name to the DTO class name automatically.

Use RepositoryType.Custom to get a partial scaffold backed by Gener8.RepositoryBase<TModel, TDto>. The constructor takes an IRepositoryContext (empty marker interface — wrap your own DB context). No CRUD methods are pre-generated; add them in a second partial class file. No extra NuGet package required.

DynamoDbRepository<TModel, TDto> implements ICompositeKeyRepository<TModel> (single- and composite-key CRUD). MongoDbRepository<TModel, TDto> implements IRepository<TModel>. All abstract bases are emitted only when at least one DTO requests them, so no SDK-type references leak into projects that do not use repositories.

The AWSSDK.DynamoDBv2 or MongoDB.Driver package must be referenced in the consuming project for DynamoDb/MongoDb respectively.

Documentation

Document Contents
Getting started Installation, project setup, first DTO
Features All features with full code examples
Attribute reference Complete API reference for every attribute and parameter
How it works Generator internals and Roslyn pipeline
Contributing Build, test, NuGet packaging, CI/CD

Building from source

dotnet build src/Gener8/Gener8.csproj
dotnet test

License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.2 0 8/16/2026
0.1.1 0 8/15/2026
0.1.0 0 8/15/2026
0.0.1 39 8/13/2026
0.0.0-beta.1 43 8/12/2026