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; }
}
This scenario is very usefull when you cannot modify the class to annotate it.
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
{
}
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}");
}
}
}