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

amis92 opened this issue Apr 4, 2017 · 0 comments

Add ability to generate Builder struct #3

amis92 opened this issue Apr 4, 2017 · 0 comments


Copy link

@amis92 amis92 commented Apr 4, 2017

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


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);


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 added the enhancement label Apr 4, 2017
@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
@amis92 amis92 closed this in #24 Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.