tomasslavicek

IsolatedStorageSettings helper class

Jul 27th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO.IsolatedStorage;
  5.  
  6. namespace EasyPhone.Helpers
  7. {
  8.     /// <summary>
  9.     /// Pomocná třída pro IsolatedStorage... (pro jednodušší ukládání / načítání)
  10.     /// - uloží do paměti, pokud tam ještě není, automaticky vytvoří položku...
  11.     /// </summary>
  12.     public static class IsoStorage
  13.     {
  14.         /// <summary>
  15.         /// Uloží do storage, nebo přepíše již uloženou hodnotu
  16.         /// </summary>
  17.         public static void Save(string key, object value)
  18.         {
  19.             var storage = IsolatedStorageSettings.ApplicationSettings;
  20.             if (storage.Contains(key))
  21.                 storage[key] = value;
  22.             else
  23.                 storage.Add(key, value);
  24.         }
  25.  
  26.         /// <summary>
  27.         /// Načte hodnotu ze Storage, nebo vrátí default hodnotu
  28.         /// </summary>
  29.         public static T Load<T>(string key)
  30.         {
  31.             var storage = IsolatedStorageSettings.ApplicationSettings;
  32.             if (storage.Contains(key))
  33.                 return (T)storage[key];
  34.             else
  35.                 return default(T);
  36.         }
  37.  
  38.         /// <summary>
  39.         /// Vrátí, jestli daný string ve Storage existuje
  40.         /// </summary>
  41.         public static bool Contains(string key)
  42.         {
  43.             var storage = IsolatedStorageSettings.ApplicationSettings;
  44.             return storage.Contains(key);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment