独立したストレージヘルプクラス

4872 ワード

    public class PersistHelper
    {
        public static string lastClickTime = "last_time";
        public static DateTime defaultTime = new DateTime(1977, 1, 1);
        /// <summary>
        ///  key ,   , 
        /// </summary>
        /// <typeparam name="T"> </typeparam>
        /// <param name="Key"> </param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static T LoadSetttingFromStorage<T>(string Key,T defaultValue)
        {
            T ObjToLoad = default(T);

            if (IsolatedStorageSettings.ApplicationSettings.Contains(Key))
            {
                ObjToLoad = (T)IsolatedStorageSettings.ApplicationSettings[Key];
            }
            else
            {
                ObjToLoad = defaultValue;
            }

            return ObjToLoad;
        }
        /// <summary>
        ///  
        /// </summary>
        /// <param name="Key"></param>
        /// <param name="Setting"></param>
        public static void SaveSettingToStorage(string Key, object Setting)
        {
            if (!IsolatedStorageSettings.ApplicationSettings.Contains(Key))
            {
                IsolatedStorageSettings.ApplicationSettings.Add(Key, Setting);
            }
            else
            {
                IsolatedStorageSettings.ApplicationSettings[Key] = Setting;
            }

            IsolatedStorageSettings.ApplicationSettings.Save();
        }

        public static bool IsSettingPersisted(string Key)
        {
            return IsolatedStorageSettings.ApplicationSettings.Contains(Key);
        }