Created
February 1, 2012 03:48
-
-
Save dbeattie71/1714966 to your computer and use it in GitHub Desktop.
IsolatedStorageSettings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO.IsolatedStorage; | |
using Gmp.Core.Model; | |
namespace Gmp.Core | |
{ | |
public class Helper | |
{ | |
private static readonly IsolatedStorageSettings Settings = IsolatedStorageSettings.ApplicationSettings; | |
public static AppSettings GetAppSettings() | |
{ | |
AppSettings appSettings; | |
var result = TryGetSetting("AppSettings", out appSettings); | |
return result ? appSettings : new AppSettings(); | |
} | |
public static void SaveAppSettings(AppSettings appSettings) | |
{ | |
StoreSetting("AppSettings", appSettings); | |
} | |
public static void StoreSetting(string settingName, string value) | |
{ | |
StoreSetting<string>(settingName, value); | |
} | |
public static void StoreSetting<TValue>(string settingName, TValue value) | |
{ | |
if (!Settings.Contains(settingName)) | |
Settings.Add(settingName, value); | |
else | |
Settings[settingName] = value; | |
Settings.Save(); | |
} | |
public static bool TryGetSetting<TValue>(string settingName, out TValue value) | |
{ | |
if (Settings.Contains(settingName)) | |
{ | |
value = (TValue) Settings[settingName]; | |
return true; | |
} | |
value = default(TValue); | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment