Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ private SettingsProperty CreateSetting(PropertyInfo propertyInfo)
// level and also property level, the latter overrides the former
// for a given setting. This is exactly the behavior we want.

settingsProperty.Attributes.Add(attribute.GetType(), attribute);
settingsProperty.Attributes[attribute.GetType()] = attribute;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,37 @@ public override void Initialize(string name, NameValueCollection config)

}

#nullable enable
public class SettingsWithNullableAttribute : ApplicationSettingsBase
{
[ApplicationScopedSetting]
public string StringProperty
{
get
{
return (string)this[nameof(StringProperty)];
}
set
{
this[nameof(StringProperty)] = value;
}
}

[UserScopedSetting]
public string? NullableStringProperty
{
get
{
return (string)this[nameof(NullableStringProperty)];
}
set
{
this[nameof(NullableStringProperty)] = value;
}
}
}
#nullable disable

private class PersistedSimpleSettings : SimpleSettings
{
}
Expand Down Expand Up @@ -315,5 +346,27 @@ public void OnSettingsLoaded_QueryProperty()
Assert.Equal(newStringPropertyValue, settings.StringProperty);
Assert.True(loadedFired);
}

[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Not fixed on NetFX")]
[Fact]
public void SettingsProperty_SettingsWithNullableAttributes_Ok()
{
SettingsWithNullableAttribute settings = new SettingsWithNullableAttribute();

Assert.Null(settings.NullableStringProperty);

string newValue = null;

settings.SettingChanging += (object sender, SettingChangingEventArgs e)
=>
{
newValue = (string)e.NewValue;
};

settings.NullableStringProperty = "test";

Assert.Equal("test", newValue);
Assert.Equal(newValue, settings.NullableStringProperty);
}
}
}