-
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
Pass the correct parameter value to the method #9361
Conversation
public T Get<T>(string key, T defaultValue, string sharedName) => | ||
_preferences.Get<T>(key, default, sharedName); | ||
_preferences.Get<T>(key, defaultValue, sharedName); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is it! Oh dear.
I must be interpreting how Preferences.Get() is supposed to work. I cannot seem to find any official documentation, however, the intellisense within Visual Studio displays the following: which I am taking to mean, "If the given preferences key is NOT found, then the given defaultValue will be returned". So I ran the following tests using the Windows Machine simulator: Preferences.Clear();
Debug.WriteLine( "String test:" );
String str_default_val = "default";
String str_val = Preferences.Get( "string_key", str_default_val);
if ( str_val == str_default_val )
{
Debug.WriteLine( "- Passed" );
}
else
{
if ( str_val is null )
{
Debug.WriteLine( $"* FAILED: str_val: null, expecting: {str_default_val}" );
}
else
{
Debug.WriteLine( $"* FAILED: str_val: {str_val}, expecting: {str_default_val}" );
}
}
Debug.WriteLine( "Boolean test:" );
Boolean bool_default_val = true;
Boolean bool_val = Preferences.Get( "boolean_key", bool_default_val );
if ( bool_val == bool_default_val )
{
Debug.WriteLine( "- Passed" );
}
else
{
Debug.WriteLine( $"* FAILED: bool_val: {bool_val}, expecting: {bool_default_val}" );
}
Debug.WriteLine( "Int32 test:" );
Int32 int32_default_val = 123;
Int32 int32_val = Preferences.Get( "int32_key", int32_default_val );
if ( int32_val == int32_default_val )
{
Debug.WriteLine( "- Passed" );
}
else
{
Debug.WriteLine( $"* FAILED: int32_val: {int32_val}, expecting: {int32_default_val}" );
} Output Displayed:
Clearly, on Windows, the Preferences.Get() method is returning the variable type default -- NOT the defaultValue given in the Get() method. When run using the Android simulator, I get the following output:
Which is the correct behavior? |
Can you open a new issue? Be sure to include the dotnet and workload versions (info for getting this is in the template). |
Description of Change
In the effort to improve unpackaged support (#8536), I inadvertently broke Preferences on Windows because of a typo:
default
instead ofdefaultValue
. This got through because our tests were correct, but coincidentally used the same value fordefaultValue
that was alsodefault
.Issues Fixed
Fixes #9338