Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to generate Builder struct #3

Closed
amis92 opened this issue Apr 4, 2017 · 0 comments
Closed

Add ability to generate Builder struct #3

amis92 opened this issue Apr 4, 2017 · 0 comments
Assignees
Milestone

Comments

@amis92
Copy link
Owner

amis92 commented Apr 4, 2017

Builder would allow for easier instantiation in tree structures or multiple mutations (close to ImmutalbeList<T>.Builder), eg.

for:

partial class Person
{
  string FirstName { get; }
  Address PrimaryAddress { get; }
}

generator would provide, in addition to primary ctor, mutators and collection mutators, a builder:

partial class Person
{
  Builder ToBuilder() => new Builder { FirstName = FirstName, PrimaryAddress = PrimaryAddress };
  struct Builder
  {
    Builder(Person original)
    {
      FirstName = original.FirstName;
      PrimaryAddress = original.PrimaryAddress;
    }
    string FirstName { get; set; }
    Address PrimaryAddress { get; set; }
    Person ToRecord() => new Person(FirstName, PrimaryAddress);
  }
}

Usage

var person = GetVIP();
var newAddress = GetNewAddress();
var relocated = new Person.Builder(person) { PrimaryAddress = newAddress }.Build();

Of course the example above might easily be shortened as var relocated = person.WithPrimaryAddress(newAddress); but this is more useful when updating many properties at the same time.

@amis92 amis92 self-assigned this Apr 4, 2017
@amis92 amis92 modified the milestones: v0.1, Future Apr 4, 2017
@amis92 amis92 removed their assignment Apr 9, 2017
@amis92 amis92 modified the milestones: Future, 0.3.0 Jan 17, 2018
@amis92 amis92 self-assigned this Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant