From 9042702c09d8582ff5fca3d3ef1049c5598942e0 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 28 Mar 2019 14:01:36 -0400 Subject: [PATCH] use formatted key --- .../Services/PreferencesStorageService.cs | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Core/Services/PreferencesStorageService.cs b/src/Core/Services/PreferencesStorageService.cs index 36896f5f8..0fc5a7682 100644 --- a/src/Core/Services/PreferencesStorageService.cs +++ b/src/Core/Services/PreferencesStorageService.cs @@ -19,27 +19,27 @@ namespace Bit.Core.Services var objType = typeof(T); if(objType == typeof(string)) { - var val = Xamarin.Essentials.Preferences.Get(key, default(string)); + var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(string)); return Task.FromResult((T)(object)val); } else if(objType == typeof(int)) { - var val = Xamarin.Essentials.Preferences.Get(key, default(int)); + var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(int)); return Task.FromResult((T)Convert.ChangeType(val, objType)); } else if(objType == typeof(long)) { - var val = Xamarin.Essentials.Preferences.Get(key, default(long)); + var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(long)); return Task.FromResult((T)Convert.ChangeType(val, objType)); } else if(objType == typeof(double)) { - var val = Xamarin.Essentials.Preferences.Get(key, default(double)); + var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(double)); return Task.FromResult((T)Convert.ChangeType(val, objType)); } else if(objType == typeof(DateTime)) { - var val = Xamarin.Essentials.Preferences.Get(key, default(DateTime)); + var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(DateTime)); return Task.FromResult((T)Convert.ChangeType(val, objType)); } else @@ -50,31 +50,32 @@ namespace Bit.Core.Services public Task SaveAsync(string key, T obj) { + var formattedKey = string.Format(_keyFormat, key); if(obj == null) { - return RemoveAsync(key); + return RemoveAsync(formattedKey); } var objType = typeof(T); if(objType == typeof(string)) { - Xamarin.Essentials.Preferences.Set(key, obj as string); + Xamarin.Essentials.Preferences.Set(formattedKey, obj as string); } else if(objType == typeof(int)) { - Xamarin.Essentials.Preferences.Set(key, (obj as int?).Value); + Xamarin.Essentials.Preferences.Set(formattedKey, (obj as int?).Value); } else if(objType == typeof(long)) { - Xamarin.Essentials.Preferences.Set(key, (obj as long?).Value); + Xamarin.Essentials.Preferences.Set(formattedKey, (obj as long?).Value); } else if(objType == typeof(double)) { - Xamarin.Essentials.Preferences.Set(key, (obj as double?).Value); + Xamarin.Essentials.Preferences.Set(formattedKey, (obj as double?).Value); } else if(objType == typeof(DateTime)) { - Xamarin.Essentials.Preferences.Set(key, (obj as DateTime?).Value); + Xamarin.Essentials.Preferences.Set(formattedKey, (obj as DateTime?).Value); } else { @@ -85,9 +86,10 @@ namespace Bit.Core.Services public Task RemoveAsync(string key) { - if(Xamarin.Essentials.Preferences.ContainsKey(key)) + var formattedKey = string.Format(_keyFormat, key); + if(Xamarin.Essentials.Preferences.ContainsKey(formattedKey)) { - Xamarin.Essentials.Preferences.Remove(key); + Xamarin.Essentials.Preferences.Remove(formattedKey); } return Task.FromResult(0); }