Пример #1
0
        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);
        }
Пример #2
0
 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();
     }
 }
Пример #3
0
        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);
        }
Пример #4
0
        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));
        }
Пример #5
0
        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());
                    }
            }
        }