Start Debugging
2012-11-03 Aktualisiert 2023-11-05 windows-phone Edit on GitHub

IsolatedStorageSettings-Helper für Windows Phone

Eine einfache IsolatedStorageSettingsHelper-Klasse für Windows Phone mit Methoden zum Abrufen, Speichern und Massen-Speichern von Items in IsolatedStorageSettings.

Ich habe beschlossen, eine wirklich einfache Helper-Klasse zu teilen, die ich in meinen Windows-Phone-Apps häufig verwende. Sie heißt IsolatedStorageSettingsHelper und hat nur drei Methoden:

Das ist nicht viel, aber das ist alles, was ich für meine Apps je gebraucht habe. Hoffentlich hilft es. Der Code folgt unten.

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.

< Zurück