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

Add helper methods to DBusValue to reduce casting. #346

Merged
merged 2 commits into from
Jun 27, 2022

Conversation

robert-ancell
Copy link
Contributor

The intention was to make helper methods to reduce the amount of typing and brackets required when using casting. However, I wanted to make it clear that it still is casting internally, which is why the methods are all prefixed with 'as'.

Not sure if the documentation on the methods is the best, but found it difficult to come up with better words than 'Converts' and 'Extracts'. Some types are just a cast because this can't be natively represented, while others are just simple types.

@robert-ancell robert-ancell requested a review from jpnurmi June 23, 2022 00:40
Copy link
Contributor

@jpnurmi jpnurmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! This makes a big difference in how convenient it is to read the values. 👍

Given that the new API is for convenient reading of the contained values, I'd propose following the (this as DBusType).value/children pattern for DBusMaybe, DBusArray, and DBusDict too. The old syntax would be ok for the (rare?) cases when there's a need to access the containing DBus type.

lib/src/dbus_value.dart Outdated Show resolved Hide resolved
lib/src/dbus_value.dart Outdated Show resolved Hide resolved
lib/src/dbus_value.dart Outdated Show resolved Hide resolved
@robert-ancell robert-ancell force-pushed the dbus-value-as-methods branch from 2e944e2 to e20dcb8 Compare June 27, 2022 00:04
@robert-ancell
Copy link
Contributor Author

Awesome! This makes a big difference in how convenient it is to read the values. +1

Given that the new API is for convenient reading of the contained values, I'd propose following the (this as DBusType).value/children pattern for DBusMaybe, DBusArray, and DBusDict too. The old syntax would be ok for the (rare?) cases when there's a need to access the containing DBus type.

I did it because I thought we would be losing useful information, but as you point out you can manually cast if necessary. Also the normal usage is to test the signature of the top-level object, which means all the sub-objects should have the signatures you expect.

@robert-ancell robert-ancell merged commit 04ca8cd into canonical:main Jun 27, 2022
@robert-ancell robert-ancell deleted the dbus-value-as-methods branch June 27, 2022 00:07
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

Successfully merging this pull request may close these issues.

2 participants