-
Notifications
You must be signed in to change notification settings - Fork 23
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
Builders should provide accessors to their fields #966
Comments
That's a good fundamental question. It's not impossible to do, certainly something like name is easy. @alorenzen and @natebosch, WDUT? |
I'm curious how often this comes up. When you create the I could get on board with the idea, though I think in many cases it might be better to go |
Is this similar/related to #964? |
@natebosch Yeah, creating the two lists (or more, if, e.g., you also want to generate class fields) is a solution. However, it either requires tighter coupling or additional custom data structures for storing information about parameters/fields. A simple example: var params = data.where(_accept).map<ParameterBuilder>(_createParam).toList();
var args = params.where(_pass).map<ExpressionBuilder>(_createArg).toList(); But since I can't use class MyParam { var type; var name; }
var paramData = data.where(_accept).map<MyParam>(_createParamData).toList();
var params = paramData.map<ParameterBuilder>(_createParam).toList();
var args = paramData.where(_pass).map<ExpressionBuilder>(_createArg).toList(); Or avoid list comprehensions and instead run a single loop that couples the two constructions. |
I can see your point. If he had nice Tuples or something this would be easier, but having to define a class is a lot of overhead. I think this feature is worth adding. Side note: In your examples all of the generic arguments to |
Yeah, I can definitely see some value to this. |
Alright, SGTM. |
I'm going to add |
Partial support towards https://github.com/dart-lang/code_builder/issues/43
* Add for/for-in loop Closes https://github.com/dart-lang/code_builder/issues/49 * Add support for while/do-while * Add constructor initializers Closes https://github.com/dart-lang/code_builder/issues/50 * Update CHANGELOG and pubspec for beta * Add “name” getter for ParameterBuilder Partial support towards https://github.com/dart-lang/code_builder/issues/43 * Update CHANGELOG * Address feedback
Aye! |
Closing for now, we can re-open for specific needs. |
* Add for/for-in loop Closes https://github.com/dart-lang/code_builder/issues/49 * Add support for while/do-while * Add constructor initializers Closes https://github.com/dart-lang/code_builder/issues/50 * Update CHANGELOG and pubspec for beta * Add “name” getter for ParameterBuilder Partial support towards https://github.com/dart-lang/code_builder/issues/43 * Update CHANGELOG * Address feedback
For example, imagine I was to construct a
factory
that forwards its parameters to a constructor:To generate
factory Foo(A a, B b, C c)
I will have aList<ParameterBuilder>
. To forward the parameters toFoo._
, I want to be able to convertList<ParameterBuilder>
to aList<ExpressionBuilder> args
and pass that tomyType.newInstance(args)
.Example:
Unfortunately
p.name
does not exist.The text was updated successfully, but these errors were encountered: