BuilderPatternGenerator 1.0.13

There is a newer version of this package available.
See the version list below for details.
dotnet add package BuilderPatternGenerator --version 1.0.13                
NuGet\Install-Package BuilderPatternGenerator -Version 1.0.13                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BuilderPatternGenerator" Version="1.0.13" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BuilderPatternGenerator --version 1.0.13                
#r "nuget: BuilderPatternGenerator, 1.0.13"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BuilderPatternGenerator as a Cake Addin
#addin nuget:?package=BuilderPatternGenerator&version=1.0.13

// Install BuilderPatternGenerator as a Cake Tool
#tool nuget:?package=BuilderPatternGenerator&version=1.0.13                

Builder Pattern Code Generation for .NET

NuGet
Deploy

This tool is designed to simplify the process of creating builders pattern for your classes, structs, or records. Unlike traditional builder generation tools, our approach focuses on immutability and ease of use. We've incorporated features that make building objects even more convenient and user-friendly.

Table of Contents

Introduction

The Builder Pattern Code Generation tool is designed with the modern developer in mind. It automates the process of creating builder patterns for your types while promoting immutability and a user-friendly experience. The tool exposed steps of building the mandatory information before proceeding to optional steps, ensuring your objects are built with all the necessary data.

Features

  • Immutability: The generated builders follow an immutable approach, ensuring the integrity of your objects, and reusable of a builder for creating a multiples lightly different objects.
  • Step-by-Step Building: The builder guides you through the process, requiring mandatory fields before proceeding to optional ones.
  • Hidden Used Stages: Already used stages are hidden, streamlining the building process and reducing complexity.
  • Clean and Readable Code: The generated code is well-organized and easy to understand, making maintenance a breeze.
  • Saves Development Time: Automating builder creation saves you time and effort, allowing you to focus on Type's data rather on the Builder techniques.

Getting Started

To start using the Builder Pattern Code Generation tool, follow these simple steps:

  1. Installation: Include the NuGet of the builder generation and the abstraction libraries:
dotnet add package BuilderPatternGenerator 
dotnet add package BuilderPatternGenerator.Abstractions
  1. Decorate Your Type: Mark the class, struct, or record you want to generate a builder for with the [GenerateBuilderPattern] attributes. This signals the generator to create the builder for your type.

Usage

Using the generated builder is intuitive and straightforward. Here's a basic example:

// PersonBuilder.cs
[GenerateBuilderPattern]
public partial record PersonBuilder(int Id, string Name)
{
    public required string Email { get; init; }
    public DateTime Birthday { get; init; }
}

Don't forget to mark the Type as partial

[Fact]
public void PersonBuilder_Test()
{
    DateTime dateTime = DateTime.Now.AddYears(-32);
    var p1 = PersonBuilder.CreateBuilder()
                    .AddName("Joe")
                    .AddId(3)
                    .AddEmail("joe16272@gmail.com")
                    .AddBirthday(dateTime)
                    .Build();

    Assert.Equal(p1, new PersonBuilder(3, "Joe") { Email = "joe16272@gmail.com", Birthday = dateTime });
}

Examples

For more comprehensive examples, check out the Bnaya.BuilderPatternGenerator.SrcGen.Playground project in our GitHub repository. These examples cover various scenarios, demonstrating the power and flexibility of our Builder Pattern Code Generation tool.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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.15 334 8/22/2023
1.0.14 238 8/22/2023
1.0.13 224 8/22/2023
1.0.12 249 8/22/2023
1.0.11 230 8/22/2023
1.0.10 217 8/22/2023