/// <summary> /// 根据 Key 移除一个 Json 对象 /// </summary> /// <param name="key"></param> public void RemovePersist(string key) { lock (persistLock) { var delPersist = Persists.FirstOrDefault(s => s.Key == key); if (delPersist != null) { Persists.Remove(delPersist); } SaveChanges(); } }
/// <summary> /// 将表中的 Json 对象反序列化成对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <returns></returns> public T Restore <T>(string key) { lock (persistLock) { var ret = default(T); var persist = Persists.FirstOrDefault(p => p.Key == key); if (persist != null) { var json = persist.Json; ret = JsonConvert.DeserializeObject <T>(json); } return(ret); } }