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

custom setters and null replacement for legacy "builder" situations #1487

Open
swn1 opened this issue Oct 11, 2023 · 0 comments
Open

custom setters and null replacement for legacy "builder" situations #1487

swn1 opened this issue Oct 11, 2023 · 0 comments

Comments

@swn1
Copy link

swn1 commented Oct 11, 2023

Working on replacing a whole ton of high-arity constructor and method overloads for a moderately complex hierarchy of "do the thing" classes using a DoTheThingParameters immutable. Some of the setters need to be polymorphic, eg accepting an enum member or a string. Some are in exclusive-or groups, eg a value or a formula for computing the value at runtime. And some have legacy callsites that (sometimes) pass null to mean "use default". And icing on the cake, I need a "setter" that parses command-line style string arguments. I found the issue thread from 2015 that documents the pattern for extending the builder interface and that's doing everything I need except I can't make nullable+default work as I'd like.

Proposal: add a parameter to Value.Default(replaceNulls = true) so that the default getter is called if the underlying value is null or not set. I could probably do it with some other combination of hidden, computed and forwarded attributes but just thought I'd run this up the flagpole. I'm coding around the problem for now.

Also, I think there should be an easier-to-find write-up of this pattern. I'll submit at least an annotated example as a PR for this ticket if you like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant