-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Record typdefs? #29
Comments
There's no reflection for 'typedef' yet, and also I haven't tested it with records yet. A full support for records is already planned, but I haven't realized the use with typedef. If you can provide a full use case, with complex examples, it can help the planning. Best regards. |
Sure, I basically use typedefs with records to define simple data classes. typedef User = ({
String name,
int age,
});
// You can add extension methods or properties
extension UserExtensions on User {
String get description {
return '$name $age';
}
bool isOlder(User other) {
return age > other.age;
}
}
void main() {
final User user1 = (name: 'John', age: 34);
final User user2= (name: 'Bob', age: 32);
final isUser1Older = user1.isOlder(user2);
print('${user1.description} ${user2.description} : $isUser1Older');
} So the typedef is just a "shortcut" for the record type. It just makes it you avoid repeating the full record type each time. But I actually use them as I would use real types. That said, If the reflection bridge works for the record type, it should work for the typedef of this same record type. |
Nice, Please add this approach to this thread, since no one mentioned it yet: Now there's a proposal for data classes: |
Could you demonstrate how you intend to utilize Just getting the list of fields? Since there's no reflection for extensions yet. |
I would use it only for record properties, not for extension methods! It is mainly to display the tree of data in the application. |
Speaking about a tree of data: maybe this can be helpful to generate the tree for console: |
Hello!
Thanks for this useful package!
Would it be possible to generate reflectors for record typedefs like the following one?
Thanks
The text was updated successfully, but these errors were encountered: