Esempio n. 1
0
 public void JsonDeserialize()
 {
     string json = File.ReadAllText("D:\\OOP\\Lab_14\\Lab_14\\bin\\Debug\\json.json");
      Textbook book = JsonConvert.DeserializeObject< Textbook>(json);
     Console.ForegroundColor = ConsoleColor.Green;
     Console.WriteLine("Объект десериализован");
     Console.ResetColor();
     Console.WriteLine(book.ToString());
 }
Esempio n. 2
0
 public void BinDeserialize()
 {
     BinaryFormatter formatter = new BinaryFormatter();
     using (FileStream file = new FileStream("bin.dat", FileMode.OpenOrCreate))
     {
          Textbook Book = (Textbook)formatter.Deserialize(file);
         Console.ForegroundColor = ConsoleColor.Green;
         Console.WriteLine("Объект десериализован");
         Console.ResetColor();
         Console.WriteLine(Book.ToString());
     }
 }
Esempio n. 3
0
 public void XmlSerialize()
 {
     Textbook book1 = new  Textbook();
     book1.NameOfBook = "LiveForEver";
      Textbook book2 = new  Textbook();
      Textbook book3 = new  Textbook();
      Textbook book4 = new  Textbook();
      Textbook[] books = new  Textbook[] { book1, book2, book3, book4};
     XmlSerializer x = new XmlSerializer(typeof( Textbook[]));
     using (FileStream fs = new FileStream("books.xml", FileMode.OpenOrCreate))
     {
         x.Serialize(fs, books);
     }
 }
Esempio n. 4
0
 public void SoapDeserialize()
 {
     SoapFormatter formatter = new SoapFormatter();
     using (FileStream file = new FileStream("soap.soap", FileMode.OpenOrCreate))
     {
         List<Textbook> list = new List<Textbook>();
         Textbook Book = new Textbook();
         for (int i = 0; i < 4; i++)
         {
             list.Add((Textbook)formatter.Deserialize(file));
         }
         Console.ForegroundColor = ConsoleColor.Green;
         Console.WriteLine("Объект десериализован");
         Console.ResetColor();
         Console.WriteLine(Book.ToString());
     }
 }