Gener8 0.0.1
See the version list below for details.
dotnet add package Gener8 --version 0.0.1
NuGet\Install-Package Gener8 -Version 0.0.1
<PackageReference Include="Gener8" Version="0.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Gener8" Version="0.0.1" />
<PackageReference Include="Gener8"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Gener8 --version 0.0.1
#r "nuget: Gener8, 0.0.1"
#:package Gener8@0.0.1
#addin nuget:?package=Gener8&version=0.0.1
#tool nuget:?package=Gener8&version=0.0.1
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
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 |
See doc/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().
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
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 |