Gener8 1.0.0
dotnet add package Gener8 --version 1.0.0
NuGet\Install-Package Gener8 -Version 1.0.0
<PackageReference Include="Gener8" Version="1.0.0" />
<PackageVersion Include="Gener8" Version="1.0.0" />
<PackageReference Include="Gener8" />
paket add Gener8 --version 1.0.0
#r "nuget: Gener8, 1.0.0"
#:package Gener8@1.0.0
#addin nuget:?package=Gener8&version=1.0.0
#tool nuget:?package=Gener8&version=1.0.0
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.
Installation
dotnet add package Gener8
This single package includes both the Roslyn source generator and Gener8.Abstractions (attributes, enums, repository contracts). No additional install is needed for basic DTO generation.
DynamoDB repositories:
dotnet add package Gener8.Extensions.DynamoDB
MongoDB repositories:
dotnet add package Gener8.Extensions.MongoDB
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; }
}
The set/init accessor, the required modifier, and property initializers are preserved exactly as declared on the source model. Get-only properties are excluded unless they are set via a detected constructor (positional records, or any class with a matching constructor), in which case they are emitted with init and ToModel uses constructor-style initialization.
Features
| Feature | Attribute / Parameter |
|---|---|
| Exclude specific properties | Ignore = [nameof(Model.Prop)] |
| Map a nested type to a DTO type | [TypeMapping(typeof(Address), typeof(AddressDto))] |
| Auto-map and generate companion DTOs | DtoNamespaces = ["MyApp.Models"] |
| Suppress a single auto type mapping | [IgnoreTypeMapping(typeof(T))] |
| 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")] |
| Make non-nullable properties nullable in the DTO | ForceNullable = [nameof(Model.Prop)] |
| Mapping extension methods | Generated automatically alongside every DTO |
| Generate a repository scaffold | Repository = RepositoryType.DynamoDb, RepositoryType.MongoDb, or RepositoryType.Custom |
| Dictionary properties with type-remapped keys/values | Handled automatically; extensions use ToDictionary(...) |
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
// {
// [return: NotNullIfNotNull(nameof(dto))]
// public static Product? ToModel(this ProductDto? dto) => dto is null ? null : new Product { ... };
// [return: NotNullIfNotNull(nameof(model))]
// public static ProductDto? ToDto (this Product? model) => model is null ? null : new ProductDto { ... };
// }
// 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 ProductRepository.g.cs:
// internal partial class ProductRepository : Gener8.DynamoDbRepository<Product, ProductDto>
// {
// public ProductRepository(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>. These abstract bases come from the extension packages rather than generated source.
The AWSSDK.DynamoDBv2 or MongoDB.Driver package must be referenced in the consuming project for DynamoDb/MongoDb respectively. Also add Gener8.Extensions.DynamoDB or Gener8.Extensions.MongoDB which provides the abstract base classes (DynamoDbRepository<TModel,TDto>, MongoDbRepository<TModel,TDto>) and converters.
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
dotnet test
To build individual packages:
dotnet build src/Gener8.Abstractions/Gener8.Abstractions.csproj
dotnet build src/Gener8/Gener8.csproj
dotnet build src/Gener8.Extensions.DynamoDB/Gener8.Extensions.DynamoDB.csproj
dotnet build src/Gener8.Extensions.MongoDB/Gener8.Extensions.MongoDB.csproj
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.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 |
|---|---|---|
| 1.0.0 | 105 | 9/5/2026 |
| 0.2.2 | 96 | 9/3/2026 |
| 0.2.1 | 81 | 8/31/2026 |
| 0.2.0 | 83 | 8/31/2026 |
| 0.2.0-beta.1 | 55 | 8/31/2026 |
| 0.1.7 | 93 | 8/31/2026 |
| 0.1.6 | 99 | 8/21/2026 |
| 0.1.5 | 101 | 8/21/2026 |
| 0.1.4 | 98 | 8/21/2026 |
| 0.1.3 | 99 | 8/16/2026 |
| 0.1.2 | 113 | 8/16/2026 |
| 0.1.1 | 99 | 8/15/2026 |
| 0.1.0 | 110 | 8/15/2026 |
| 0.0.1 | 99 | 8/13/2026 |
| 0.0.0-beta.1 | 72 | 8/12/2026 |