Skip to content

Latest commit

 

History

History
47 lines (40 loc) · 1.09 KB

PackageReadme.md

File metadata and controls

47 lines (40 loc) · 1.09 KB

Usage

1️⃣ Annotate a class

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

[AutoGenerateBuilder]
public class User
{
    public string FirstName { get; set; }

    public string LastName { get; set; }

    public DateTime? Date { get; set; }
}

2️⃣ Define a class which needs to act as a builder

This scenario is very usefull when you cannot modify the class to annotate it.

Create a public and partial builder class

And annotate this class with [AutoGenerateBuilder(typeof(XXX))] where XXX is the type for which you want to generate a FluentBuilder.

[AutoGenerateBuilder(typeof(UserDto))]
public partial class MyUserDtoBuilder
{
}

Use FluentBuilder

using System;

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

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