diff --git a/src/MauiSettings/Helper/MauiSettingsHelper.cs b/src/MauiSettings/Helper/MauiSettingsHelper.cs index 44fcde6..e131266 100644 --- a/src/MauiSettings/Helper/MauiSettingsHelper.cs +++ b/src/MauiSettings/Helper/MauiSettingsHelper.cs @@ -16,7 +16,7 @@ internal class MauiSettingsHelper * - String * - DateTime */ - public static T GetSettingsValue(string key, T defaultValue) + public static T? GetSettingsValue(string key, T defaultValue) { object? returnValue = null; try @@ -73,17 +73,18 @@ public static T GetSettingsValue(string key, T defaultValue) //return (T)Convert.ChangeType(returnValue, typeof(T)); } - public static T ChangeSettingsType(object settingsValue, T defaultValue) => (T)Convert.ChangeType(settingsValue, typeof(T)); + public static T? ChangeSettingsType(object settingsValue, T defaultValue) => (T)Convert.ChangeType(settingsValue, typeof(T)) ?? default; // Docs: https://docs.microsoft.com/en-us/dotnet/maui/platform-integration/storage/secure-storage?tabs=ios // Only string is allowed for secure storage - public static async Task GetSecureSettingsValueAsync(string key, string defaultValue) + public static async Task GetSecureSettingsValueAsync(string key, string? defaultValue) { + defaultValue ??= string.Empty; string? settingsObject = await SecureStorage.Default.GetAsync(key); return settingsObject == null ? defaultValue : settingsObject; } - public static void SetSettingsValue(string key, object value) + public static void SetSettingsValue(string key, object? value) { switch (value) { diff --git a/src/MauiSettings/Utilities/MauiSettingNameFormater.cs b/src/MauiSettings/Utilities/MauiSettingNameFormater.cs index 3dc046d..c47af35 100644 --- a/src/MauiSettings/Utilities/MauiSettingNameFormater.cs +++ b/src/MauiSettings/Utilities/MauiSettingNameFormater.cs @@ -16,7 +16,9 @@ internal class MauiSettingNameFormater public const string Version = "v1"; public const string NamePrefix = "AR"; #endregion - public static string GetFullSettingName(Type settingsType, MemberInfo mi, MauiSettingBaseAttribute baseSettingAttr) + + #region Methods + public static string GetFullSettingName(Type? settingsType, MemberInfo mi, MauiSettingBaseAttribute? baseSettingAttr) { string name; if (string.IsNullOrEmpty(baseSettingAttr?.Name)) @@ -30,5 +32,7 @@ public static string GetFullSettingName(Type settingsType, MemberInfo mi, MauiSe } return $"{NamePrefix}_{Version}_{name}{(settingsType == null ? "" : $"_{settingsType}")}"; } + public static string GetSettingsNamePrefix() => $"{NamePrefix}_{Version}"; + #endregion } }