-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 TryGetValue() to IPreferences #26123
Comments
Enables checking and retrieving the value in a single method call. Recommended practice for dictionaries. |
Get already has a default value for if its not found, so although the method name is different, that is basically implemented already? Or what am I missing? |
I marked the line that would go away after the requested change was implemented. Also, current API forces providing default value each time the Get() is called, so this call should be preferably made only once within the range, where the preference's value is needed.
MyPref2 uses the method |
But you don't need I mean, I see some value, but its mostly writing slightly different code to achieve the same thing you can already do today. |
If this was true, the |
For now, I've added this extension method to my codebase. It does not improve performance what a "real"
|
The TryGetValue() method has a subtle advantage because it always returns a Boolean value, making it easy to apply in various scenarios. |
I would like to pick this up if that's alright ✋ |
@egvijayanand how do I navigate to pick this up? |
You need to get approval for this work item from any one of the maintainers of this repo. |
@jeremi-przeorek you need to check out the repository an create a pull request when you are done with the coding |
IMHO, It's really easy to add this as an extension method, so devs can implement it by their own if needed and there's no need to add a new API for that on maui |
@pictos The existing API is awkward. I would create a PR and see what happens. |
Description
Currently IPreferences allows checking if the property exists via
ContainsKey(string key)
method but it would be nice if it had aTryGetValue<T>(string propertyName, out T value)
Public API Changes
Public
TryGetValue<T>(string propertyName, out T value)
would be added to the IPreferences interface.Intended Use-Case
More concise code.
The text was updated successfully, but these errors were encountered: