Start Debugging
2012-11-03 更新日 2023-11-05 windows-phone Edit on GitHub

Windows Phone 用 IsolatedStorageSettings ヘルパー

Windows Phone 向けのシンプルな IsolatedStorageSettingsHelper クラス。IsolatedStorageSettings 上のアイテムを取得、保存、まとめて保存するメソッドを提供します。

私が Windows Phone アプリでよく使っている、本当にシンプルな helper クラスを共有しようと思います。名前は IsolatedStorageSettingsHelper で、メソッドは 3 つだけです。

これだけですが、私のアプリで必要だったのはこれだけでした。お役に立てば幸いです。コードは下のとおりです。

public class IsolatedStorageSettingsHelper
{
   public static void SaveItem(string key, object item)
   {
      IsolatedStorageSettings.ApplicationSettings[key] = item;
      IsolatedStorageSettings.ApplicationSettings.Save();
   }

   public static void SaveItems(Dictionary<string, object> items)
   {
      foreach (var item in items)
         IsolatedStorageSettings.ApplicationSettings[item.Key] = item.Value;
      IsolatedStorageSettings.ApplicationSettings.Save();
   }

   public static T GetItem<T>(string key)
   {
      T item;
      try
      {
         IsolatedStorageSettings.ApplicationSettings.TryGetValue<T>(key, out item);
      }
      catch (InvalidCastException ice)
      {
         return default(T);
      }
      return item;
   }
}

Comments

Sign in with GitHub to comment. Reactions and replies thread back to the comments repo.

< 戻る