Skip to content

A project which uses Source Generation to create a FluentBuilder for a specified model or DTO

License

Notifications You must be signed in to change notification settings

danspark/FluentBuilder

 
 

Repository files navigation

FluentBuilder

A project which uses Source Generation to create a FluentBuilder for a specified model or DTO.

This project is based on Tom Phan : "auto-generate-builders-using-source-generator-in-net-5".

Install

NuGet Badge

You can install from NuGet using the following command in the package manager window:

Install-Package FluentBuilder

Or via the Visual Studio NuGet package manager or if you use the dotnet command:

dotnet add package FluentBuilder

Usage

Annotate

Annotate a DTO with [FluentBuilder.AutoGenerateBuilder] to indicate that a FLuentBuilder should be generated for this class:

[FluentBuilder.AutoGenerateBuilder]
public class UserDto
{
    public string FirstName { get; set; }

    public string LastName { get; set; }

    public DateTime? Date { get; set; }
}

Use FluentBuilder

using System;

namespace FluentBuilderConsumer
{
    class Program
    {
        static void Main(string[] args)
        {
            var user = new FluentBuilder.UserDtoBuilder()
                .WithFirstName("Test")
                .WithLastName("User")
                .Build();

            Console.WriteLine($"{user.FirstName} {user.LastName}");
        }
    }
}

About

A project which uses Source Generation to create a FluentBuilder for a specified model or DTO

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%