public static FileDatabase Deserialize(this FileDatabase db, string file) { var serializer = new XmlSerializer(typeof(FileDatabase)); FileDatabase temp = serializer.Deserialize(new StringReader(file)) as FileDatabase; db = temp; return(db); }
public static void Serialize(this FileDatabase creds, string path) { using (var writer = new System.IO.StreamWriter(path, false)) { var serializer = new XmlSerializer(typeof(FileDatabase)); serializer.Serialize(writer, creds); writer.Flush(); } }
public static FileDatabase DeserializeJsonString(this FileDatabase db, string str) { DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(FileDatabase)); byte[] file; file = Encoding.UTF8.GetBytes(str); using (MemoryStream ms = new MemoryStream(file)) db = (FileDatabase)js.ReadObject(ms); return(db); }
public static FileDatabase DeserializeJson(this FileDatabase db, string path) { string file = ""; try { using (StreamReader sr = new StreamReader(path)) { file = sr.ReadToEnd(); } } catch { } return(DeserializeJsonString(db, file)); }
public static void SerializeJson(this FileDatabase data, string path) { DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(FileDatabase)); using (MemoryStream ms = new MemoryStream()) { js.WriteObject(ms, data); ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) using (var writer = new System.IO.StreamWriter(path, false)) { writer.Write(sr.ReadToEnd()); } } }