BuilderHacker logo

BuilderHacker

.NET Build License

BuilderHacker is a .NET builder generator and runtime builder library.

Overview

Use BuilderHacker to generate fluent builders from an attribute, or use the runtime EntityBuilder<T> for reflection-based scenarios.

Features

  • Generates fluent builders from [GenerateBuilderHacker]
  • Supports private fields and private setters
  • Traverses inherited instance members
  • Supports source-generation and runtime reflection-based builder workflows
  • Includes a runtime EntityBuilder<T> for reflection-based scenarios

Projects

  • BuilderHacker.Abstraction - shared attribute and interfaces
  • BuilderHacker.Core - runtime EntityBuilder<T> library
  • BuilderHacker.Generator - incremental source generator for attribute-based builders
  • BuilderHacker.Console - sample application

Usage

Attribute-based builder

using BuilderHacker.Abstraction.Attributes;

[GenerateBuilderHacker]
public partial class TestClass
{
    public string Name { get; set; }
    public int Age { get; set; }
}

// Default generated standalone builder (Create() by default):
var obj = TestClassBuilder.Create()
    .Name("John")
    .Age(30)
    .Build();

Runtime builder

using BuilderHacker.Core.EntityBuilder;

var obj = EntityBuilder<TestClass>.Create()
    .Set(x => x.Name, "John")
    .Set(x => x.Age, 30)
    .Build();

Requirements

  • .NET Standard 2.0 for shared libraries
  • .NET 10 for the sample app and build environment

Build

dotnet build

Notes

  • Types marked with [GenerateBuilderHacker] generate a standalone builder by default.
  • To generate a partial class entry point instead, use [GenerateBuilderHacker(true)].
  • The generated API follows YourTypeBuilder.Create().PropertyName(value)...Build() by default, or YourType.Builder().PropertyName(...)...Build() when using partial-mode.