Beispiel #1
0
        public string Serialize(CarStorage carStorage, string path)
        {
            var xs = JsonConvert.SerializeObject(carStorage);

            File.WriteAllText(path, xs);
            return(xs);
        }
 public string Serialize(CarStorage carStorage, string path)
 {
     using (FileStream fs = new FileStream(path, FileMode.Create))
     {
         var xs = new XmlSerializer(typeof(CarStorage));
         xs.Serialize(fs, carStorage);
     }
     return(File.ReadAllText(path));
 }
Beispiel #3
0
 public string Serialize(CarStorage carStorage, string path)
 {
     using (FileStream fs = new FileStream(path, FileMode.Create))
     {
         BinaryFormatter bf = new BinaryFormatter();
         bf.Serialize(fs, carStorage);
     }
     return(File.ReadAllText(path));
 }
Beispiel #4
0
        public void Run()
        {
            List <Car> cars = new List <Car>()
            {
                new Car(123456, 15, 3),
                new Car(654321, 10, 1),
                new Car(456123, 5, 2)
            };
            CarStorage storage = new CarStorage(cars);

            BinarySerializer xs = new BinarySerializer();

            Logger.Write(xs.Serialize(storage, "Sereiled.txt") + "\n");

            string deserialize = "";

            foreach (var car in xs.DeSerialize("Sereiled.txt"))
            {
                deserialize += $"{car.CarId}: {car.Price} * {car.Quantity} = {car.Total}\n";
            }
            Logger.Write(deserialize);
        }