独立存储帮助类【转载】
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); }