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

Generate field names as strings similar to C# nameof operator #1167

Open
jan-siroky opened this issue Jun 18, 2022 · 2 comments
Open

Generate field names as strings similar to C# nameof operator #1167

jan-siroky opened this issue Jun 18, 2022 · 2 comments
Assignees

Comments

@jan-siroky
Copy link

I would like to ask you to consider adding functionality that would generate field names to strings that would be accessible as static members of a class or an enum.

For example I am using reactive_forms package. When defining formgroup object, I have to use string literals for map keys which creates room for errors.

FormGroup({
  'name': FormControl<String>(),
  'email': FormControl<String>(),
});

I would much rather have something like this (static class members):

FormGroup({
  User.fields.name: FormControl<String>(),
  User.fields.email: FormControl<String>(),
});

or enum style:

FormGroup({
  UserFields.name.name: FormControl<String>(),
  UserFields.email.name: FormControl<String>(),
});

This would be useful for many more use cases, but this is the main for me.

Thank you for developing this wonderful library!

@davidmorgan
Copy link
Collaborator

Hmmmmm in general I like the idea of making class metadata more usefully available.

We could create an enum for you. With dart 2.17 it could even be a real enum.

I don't often get to work on built_value features, I'll see if I can take a look at this one next time I do. Thanks.

@jan-siroky
Copy link
Author

That would be nice. Thank you for considering!

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

No branches or pull requests

2 participants