From 4ef8ccaa8ef49e3860c9d20e2f96ad6bc67ded2e Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 8 Apr 2019 20:32:12 -0400 Subject: [PATCH] support nullable preference types --- src/Core/Services/PreferencesStorageService.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Core/Services/PreferencesStorageService.cs b/src/Core/Services/PreferencesStorageService.cs index 220eeb1a5..ab6bc82e8 100644 --- a/src/Core/Services/PreferencesStorageService.cs +++ b/src/Core/Services/PreferencesStorageService.cs @@ -22,22 +22,22 @@ namespace Bit.Core.Services var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(string)); return Task.FromResult((T)(object)val); } - else if(objType == typeof(int)) + else if(objType == typeof(int) || objType == typeof(int?)) { var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(int)); return Task.FromResult((T)Convert.ChangeType(val, objType)); } - else if(objType == typeof(long)) + else if(objType == typeof(long) || objType == typeof(long?)) { var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(long)); return Task.FromResult((T)Convert.ChangeType(val, objType)); } - else if(objType == typeof(double)) + else if(objType == typeof(double) || objType == typeof(double?)) { var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(double)); return Task.FromResult((T)Convert.ChangeType(val, objType)); } - else if(objType == typeof(DateTime)) + else if(objType == typeof(DateTime) || objType == typeof(DateTime?)) { var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(DateTime)); return Task.FromResult((T)Convert.ChangeType(val, objType)); @@ -61,19 +61,19 @@ namespace Bit.Core.Services { Xamarin.Essentials.Preferences.Set(formattedKey, obj as string); } - else if(objType == typeof(int)) + else if(objType == typeof(int) || objType == typeof(int?)) { Xamarin.Essentials.Preferences.Set(formattedKey, (obj as int?).Value); } - else if(objType == typeof(long)) + else if(objType == typeof(long) || objType == typeof(long?)) { Xamarin.Essentials.Preferences.Set(formattedKey, (obj as long?).Value); } - else if(objType == typeof(double)) + else if(objType == typeof(double) || objType == typeof(double?)) { Xamarin.Essentials.Preferences.Set(formattedKey, (obj as double?).Value); } - else if(objType == typeof(DateTime)) + else if(objType == typeof(DateTime) || objType == typeof(DateTime?)) { Xamarin.Essentials.Preferences.Set(formattedKey, (obj as DateTime?).Value); }