Resolving warnings and treating warnings as errors in WinUI project. (#824)
This commit is contained in:
@@ -9,10 +9,10 @@ namespace Wino.Mail.WinUI.Services;
|
||||
|
||||
public class ConfigurationService : IConfigurationService
|
||||
{
|
||||
public T Get<T>(string key, T defaultValue = default)
|
||||
public T Get<T>(string key, T defaultValue = default!)
|
||||
=> GetInternal(key, ApplicationData.Current.LocalSettings.Values, defaultValue);
|
||||
|
||||
public T GetRoaming<T>(string key, T defaultValue = default)
|
||||
public T GetRoaming<T>(string key, T defaultValue = default!)
|
||||
=> GetInternal(key, ApplicationData.Current.RoamingSettings.Values, defaultValue);
|
||||
|
||||
public void Set(string key, object value)
|
||||
@@ -21,11 +21,13 @@ public class ConfigurationService : IConfigurationService
|
||||
public void SetRoaming(string key, object value)
|
||||
=> SetInternal(key, value, ApplicationData.Current.RoamingSettings.Values);
|
||||
|
||||
private static T GetInternal<T>(string key, IPropertySet collection, T defaultValue = default)
|
||||
private static T GetInternal<T>(string key, IPropertySet collection, T defaultValue = default!)
|
||||
{
|
||||
if (collection.TryGetValue(key, out object value))
|
||||
if (collection.TryGetValue(key, out object? value))
|
||||
{
|
||||
var stringValue = value?.ToString();
|
||||
if (string.IsNullOrWhiteSpace(stringValue))
|
||||
return defaultValue;
|
||||
|
||||
if (typeof(T).IsEnum)
|
||||
return (T)Enum.Parse(typeof(T), stringValue);
|
||||
@@ -40,7 +42,8 @@ public class ConfigurationService : IConfigurationService
|
||||
return (T)(object)TimeSpan.Parse(stringValue);
|
||||
}
|
||||
|
||||
return (T)Convert.ChangeType(stringValue, typeof(T));
|
||||
var converted = Convert.ChangeType(stringValue, typeof(T));
|
||||
return converted is T typed ? typed : defaultValue;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
|
||||
Reference in New Issue
Block a user