Safalin.BuilderGenerator 2.0.5

dotnet add package Safalin.BuilderGenerator --version 2.0.5                
NuGet\Install-Package Safalin.BuilderGenerator -Version 2.0.5                
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="Safalin.BuilderGenerator" Version="2.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Safalin.BuilderGenerator --version 2.0.5                
#r "nuget: Safalin.BuilderGenerator, 2.0.5"                
#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 Safalin.BuilderGenerator as a Cake Addin
#addin nuget:?package=Safalin.BuilderGenerator&version=2.0.5

// Install Safalin.BuilderGenerator as a Cake Tool
#tool nuget:?package=Safalin.BuilderGenerator&version=2.0.5                

A fork of BuilderGenerator, a .NET Source Generator that is designed to add fluent builder classes to your projects. Save time by automating the builder pattern.

What are Builders?

Builders are an object creation pattern, similar to the Object Mother pattern. Object Mothers and Builders are most commonly used to create objects for testing, but they can be used anywhere you want "canned" objects.

Example Usage

  1. Create a new partial class that will hold your builder methods - for this example, we'll call it FooBuilder, as the class we want to work with is called Foo.

  2. Decorate it with the BuilderFor attribute, specifying the type of class that the builder is meant to build. For example:

    [BuilderFor(typeof(Foo))]
    public partial class FooBuilder
    {
    }
    
  3. Rebuild your project. The source generator will run and autogenerate methods in a separate partial class file, for each property in the type you specified in Step 2.

    You can also add factory methods to your partial class which can craft specific data scenarios:

    [BuilderFor(typeof(Foo))]
    public partial class FooBuilder
    {
        public static FooBuilder Bar()
        {
            return new FooBuilder()
                .WithBar(true);
        }
    
        public static FooBuilder NotBar()
        {
            return new FooBuilder()
                .WithBar(false);
        }
    }
    

Features

Record types

With this fork, you can use the [BuilderFor] attribute on C# record types:

public record MyRecord(bool Hello);

[BuilderFor(typeof(MyRecord)]
public partial class MyRecordBuilder
{
}

var builder = new MyRecordBuilder().WithHello(true).Build();

WithValuesFrom

The new WithValuesFrom method allows you to copy values from an existing instance into your builder:

new MyBuilder().WithValuesFrom(anotherObject)

Documentation & Source Code

For more information, please visit the GitHub repository.

Product 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. 
.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. 
Compatible target framework(s)
Included target framework(s) (in 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
2.0.5 1,461 12/8/2023
2.0.4 185 12/1/2023
2.0.2 134 12/1/2023
2.0.1 127 12/1/2023
2.0.0 129 12/1/2023
0.1.127 130 12/1/2023
0.1.125 138 12/1/2023