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

Named constructor support #5

Open
smotastic opened this issue Jun 3, 2021 · 0 comments
Open

Named constructor support #5

smotastic opened this issue Jun 3, 2021 · 0 comments

Comments

@smotastic
Copy link
Owner

smotastic commented Jun 3, 2021

Right now the first found constructor is used for populating data initially.

ConstructorElement _chooseConstructor(
    ClassElement outputClass, ClassElement _) {
  return outputClass.constructors.where((element) => !element.isFactory).first;
}

It would be nice, if in the Mapping Annotation you can define the constructor to use.

class Bar {
  final String text;
  Bar() : this.text = 'should not be used by mapper';
  Bar.useThis(this.text);
}

@Mapper()
class Mapper {
  @Mapping(constructor='useThis')
  Foo fromBar(Bar source);
}

Generated Mapper should then use the "useThis" constructor.

In the future we might use constructor tear off, right now it's not supported by dart and only in the beta.
https://github.com/dart-lang/language/blob/master/accepted/future-releases/constructor-tearoffs/feature-specification.md

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