Open jvmlet opened 1 year ago
These builders work a little different than most. There's not an instance of an object behind the scenes that's being mutated. There are a series of lazy properties that then get applied when you finally tell it to build the final product. My builders are more like blueprints. However, I can see that by rearranging things slightly, they could move the "Object" to the head of the line and then apply the other properties after that, which might achieve what you're after. I'm in the middle of a performance and caching push these days, but I'll see what I can do.
Btw, protobuf generates obj.toBuilder()
method ... Very similar to what Lombok does
I know it's been a while, but I have a newer release for testing. v2.4.0-alpha introduces a constructor that takes in an example object. It copies the current properties in to the backing fields as well as setting the behind-the-scenes object to the one passed in. I think this covers the scenario you described. I'm still trying to decide on the final shape of things and write some more tests, but I thought you might be interested in checking out the alpha.
Great, thanks a lot.
First of all, BIG thanks for the great library, having java background and getting used to Lombok, this functionality was really missing. Should be part of
C#
compiler ;-)Suggestion :
public abstract class Builder<T> where T : Builder<T>
instead ofpublic abstract class Builder<T> where T : class
allows you to have fluent API by returning :WithObject(obj).WithSomethingElse(somethingElse).Build()
will alterSomethingElse
property of original objectobj
, but looking at generatedBuilderGenerator.Builder
, this doesn't behave like this. Would you please provide support for such use-case ? Maybe generating c'tor that getsobj
:new ConcreteBuilder(obj).WithSomethingElse(somethingElse).Build()
to be backward compatible and not interfere with .1 ?Thanks again for your work,