Trellis.AspSourceGenerator
3.0.0-alpha.99
dotnet add package Trellis.AspSourceGenerator --version 3.0.0-alpha.99
NuGet\Install-Package Trellis.AspSourceGenerator -Version 3.0.0-alpha.99
<PackageReference Include="Trellis.AspSourceGenerator" Version="3.0.0-alpha.99" />
<PackageVersion Include="Trellis.AspSourceGenerator" Version="3.0.0-alpha.99" />
<PackageReference Include="Trellis.AspSourceGenerator" />
paket add Trellis.AspSourceGenerator --version 3.0.0-alpha.99
#r "nuget: Trellis.AspSourceGenerator, 3.0.0-alpha.99"
#:package Trellis.AspSourceGenerator@3.0.0-alpha.99
#addin nuget:?package=Trellis.AspSourceGenerator&version=3.0.0-alpha.99&prerelease
#tool nuget:?package=Trellis.AspSourceGenerator&version=3.0.0-alpha.99&prerelease
Trellis.Asp Source Generator
A Roslyn source generator that automatically creates AOT-compatible JSON converters and serializer context entries for types implementing IScalarValue<TSelf, TPrimitive>.
Features
- AOT Compatible: Generated code works with Native AOT compilation
- No Reflection: All type information is resolved at compile time
- Faster Startup: No runtime type scanning or assembly reflection
- Trimming Safe: Code won't be trimmed away since it's explicitly generated
- Automatic Discovery: Finds all types implementing
IScalarValuein your assembly
Usage
Add a reference to the source generator package in your project.
Create a partial
JsonSerializerContextand mark it with[GenerateScalarValueConverters]:
using System.Text.Json.Serialization;
using Trellis;
[GenerateScalarValueConverters]
[JsonSerializable(typeof(MyDto))]
public partial class AppJsonSerializerContext : JsonSerializerContext
{
}
- The generator will automatically:
- Create AOT-compatible JSON converters for all
IScalarValue<TSelf, TPrimitive>types - Add
[JsonSerializable]attributes for all scalar value types to your context - Generate a
GeneratedScalarValueConverterFactoryyou can use directly
- Create AOT-compatible JSON converters for all
Generated Code
For each type implementing IScalarValue like:
public class CustomerId : ScalarValueObject<CustomerId, Guid>, IScalarValue<CustomerId, Guid>
{
// ...
}
The generator creates:
- A strongly-typed
CustomerIdJsonConverterclass - A
[JsonSerializable(typeof(CustomerId))]attribute on your context - Entry in
GeneratedScalarValueConverterFactoryfor automatic converter resolution
Using the Generated Factory
You can use the generated factory directly:
var options = new JsonSerializerOptions
{
TypeInfoResolver = AppJsonSerializerContext.Default
};
options.Converters.Add(new Trellis.Generated.GeneratedScalarValueConverterFactory());
Benefits Over Runtime Reflection
| Feature | Runtime Reflection | Source Generator |
|---|---|---|
| AOT Support | ❌ Not compatible | ✅ Full support |
| Startup Time | Slower (type scanning) | Faster (precompiled) |
| Trimming | May break | Trimming safe |
| Memory | Higher (reflection cache) | Lower |
| IDE Support | None | Full IntelliSense |
Requirements
- .NET 6.0 or later
- C# 10.0 or later
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 |
|---|---|---|
| 3.0.0-alpha.99 | 0 | 3/4/2026 |
| 3.0.0-alpha.98 | 32 | 3/3/2026 |
| 3.0.0-alpha.95 | 43 | 3/2/2026 |
| 3.0.0-alpha.94 | 38 | 3/2/2026 |
| 3.0.0-alpha.93 | 39 | 3/1/2026 |
| 3.0.0-alpha.92 | 41 | 2/28/2026 |
| 3.0.0-alpha.83 | 36 | 2/27/2026 |