このヘルパーメソッドを使用しており、さまざまな種類のデータ(カスタムオブジェクトも)をIsolatedStorageに保存して、簡単に取得できます。
//Helper method to save a key value pair in ISO store
internal static void SaveKeyValue<T>(string key, T value)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
IsolatedStorageSettings.ApplicationSettings[key] = value;
else
IsolatedStorageSettings.ApplicationSettings.Add(key, value);
IsolatedStorageSettings.ApplicationSettings.Save();
}
//Helper method to load a value of type T associated with the key from ISO store
internal static T LoadKeyValue<T>(string key)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
return (T)IsolatedStorageSettings.ApplicationSettings[key];
else
return default(T);
}
そして、これらのヘルパーメソッドの使用例を次に示します。
//Save your custom objects whenever you want
SaveKeyValue<MyCustomClass>("customObjectKey", customObject);
//Load your custom objects after the re activation of app..or whenever you need
MyCustomClass customObject = LoadKeyValue<MyCustomClass>("customObjectKey");