Skip to content

Instantly share code, notes, and snippets.

@dbeattie71
Created February 1, 2012 03:48
Show Gist options
  • Save dbeattie71/1714966 to your computer and use it in GitHub Desktop.
Save dbeattie71/1714966 to your computer and use it in GitHub Desktop.
IsolatedStorageSettings
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