dart-lang / code_builder

A fluent API for generating valid Dart source code
https://pub.dev/packages/code_builder
BSD 3-Clause "New" or "Revised" License
423 stars 66 forks source link

Would like a (typeless) parameter shorthand. #382

Open eseidel opened 1 year ago

eseidel commented 1 year ago

AFAICT, the shortest way to add (foo) to your parameter list is Parameter((b) => b..name = 'foo', feels like there could be something shorter? Maybe there is an I just didn't find it in the code?

eseidel commented 1 year ago

For example (and maybe this is a separate issue?) Is this the shortest way to write (value) => value.toJson()?

    var toJson = Method((m) => m
      ..requiredParameters.add(Parameter((p) => p.name = 'value'))
      ..body = refer('value').property('toJson').call([]).code).closure;
eseidel commented 1 year ago

I guess var toJson = Code('(value) => value.toJson()'); is the right way. :)