StepwiseBuilderGenerator 2.0.0
See the version list below for details.
dotnet add package StepwiseBuilderGenerator --version 2.0.0
NuGet\Install-Package StepwiseBuilderGenerator -Version 2.0.0
<PackageReference Include="StepwiseBuilderGenerator" Version="2.0.0" />
<PackageVersion Include="StepwiseBuilderGenerator" Version="2.0.0" />
<PackageReference Include="StepwiseBuilderGenerator" />
paket add StepwiseBuilderGenerator --version 2.0.0
#r "nuget: StepwiseBuilderGenerator, 2.0.0"
#:package StepwiseBuilderGenerator@2.0.0
#addin nuget:?package=StepwiseBuilderGenerator&version=2.0.0
#tool nuget:?package=StepwiseBuilderGenerator&version=2.0.0
Stepwise Builder Generator
A lightweight C# source generator that produces strongly-typed, stepwise “fluent” builders. Simply annotate a class and describe its steps; the generator emits interfaces and a partial class to guide callers through each required step.
Features
AddStep<T>(stepName, fieldName = null)
Define each required input in order.Default-value support
Supply a factory for a step so callers can use.StepName()with no arguments.BranchFrom(baseBuilder, baseStep)
Insert an alternate path from one builder into another.Enum of steps
Every generated builder includesenum Steps { … }for logging or reflection.Static factories
StepwiseBuilders.YourBuilder()to kick off a chain.
Examples
1. Basic builder
Target type:
public class Order
{
public int Id { get; init; }
public string Customer { get; init; }
public decimal Total { get; init; }
}
Builder declaration:
[StepwiseBuilder]
public partial class OrderBuilder
{
public OrderBuilder()
{
GenerateStepwiseBuilder
.AddStep<int>("SetId", "Id")
.AddStep<string>("SetCustomer")
.AddStep<decimal>("SetTotal")
.CreateBuilderFor<Order>();
}
}
Usage:
var order = StepwiseBuilders.OrderBuilder()
.SetId(123)
.SetCustomer("Acme Co.")
.SetTotal(99.95m)
.Build(o => o);
2. Default-value steps
Target type:
public class ReportConfig
{
public string Title { get; init; }
public bool IncludeCharts{ get; init; }
}
Builder declaration:
[StepwiseBuilder]
public partial class ReportConfigBuilder
{
public ReportConfigBuilder()
{
GenerateStepwiseBuilder
.AddStep<string>("WithTitle")
.AddStep<bool>("IncludeCharts", defaultValueFactory: () => true)
.CreateBuilderFor<ReportConfig>();
}
}
Usage:
// uses default IncludeCharts = true
var config = StepwiseBuilders.ReportConfigBuilder()
.WithTitle("Q1 Results")
.IncludeCharts() // no arg → defaultValueFactory invoked
.Build(c => c);
3. Branching between builders
Base builder (UserBuilder):
[StepwiseBuilder]
public partial class UserBuilder
{
public UserBuilder()
{
GenerateStepwiseBuilder
.AddStep<string>("SetName")
.AddStep<int>("SetAge")
.CreateBuilderFor<User>();
}
}
Branching builder (VipUserBuilder):
[StepwiseBuilder]
public partial class VipUserBuilder
{
public VipUserBuilder()
{
GenerateStepwiseBuilder
.BranchFrom("UserBuilder", "SetAge")
.AddStep<string>("SetMembershipLevel")
.CreateBuilderFor<VipUser>();
}
}
Usage:
// regular user
var u1 = StepwiseBuilders.UserBuilder()
.SetName("Alice")
.SetAge(30)
.Build(u => u);
// VIP user branches in after SetAge
var vip = StepwiseBuilders.UserBuilder()
.SetName("Bob")
.SetAge(45)
.SetMembershipLevel("Gold")
.Build(v => v);
FAQ
Q: Can I inject services or dependencies into a builder?
A: Yes—since the generated builders are partial classes, you’re free to add your own constructor(s) (e.g. taking ILogger, IRepository, etc.) in another partial file. Dependency-injected fields or properties will be available when the step methods run.
Q: What if I omit the fieldName in AddStep?
A: A field named {StepName}Value is generated automatically.
Q: How do I supply custom “Build” logic?
A: Call .Build(instance => /* your mapping to target */) or add extension methods on the final build interface for reusable patterns.
| 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
- Microsoft.CodeAnalysis.CSharp (>= 4.3.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.3.0)
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 |
|---|---|---|
| 4.0.0 | 230 | 6/16/2025 |
| 3.0.0 | 342 | 5/14/2025 |
| 2.2.2 | 246 | 4/28/2025 |
| 2.2.1 | 160 | 4/26/2025 |
| 2.2.0 | 183 | 4/26/2025 |
| 2.1.3 | 168 | 4/25/2025 |
| 2.1.2 | 165 | 4/25/2025 |
| 2.1.1 | 181 | 4/25/2025 |
| 2.1.0 | 228 | 4/24/2025 |
| 2.0.2 | 226 | 4/24/2025 |
| 2.0.1 | 270 | 4/24/2025 |
| 2.0.0 | 230 | 4/23/2025 |
| 1.0.6 | 562 | 3/25/2025 |
| 1.0.5 | 545 | 3/25/2025 |
| 1.0.4 | 525 | 3/24/2025 |
| 1.0.3 | 173 | 1/13/2025 |
| 1.0.2 | 161 | 1/13/2025 |
| 1.0.1 | 169 | 1/9/2025 |
| 1.0.0 | 169 | 1/9/2025 |