public void Run() { var cars = new List <Car>(); cars.Add(new Car("Audi", 100000)); cars.Add(new Car("BMW", 200000)); cars.Add(new Car("Opel", 50000)); try { var js = new JsonSerialization(cars.GetType(), "cars.txt"); var bs = new BinarySerialization(cars.GetType(), "cars.bin"); var xs = new XMLSerialization(cars.GetType(), "cars.xml"); js.Serialize(cars); bs.Serialize(cars); xs.Serialize(cars); var carsFromJSON = (List <Car>)js.Deserialize(); var carsFromXML = (List <Car>)xs.Deserialize(); var carsFromBinary = (List <Car>)bs.Deserialize(); } catch (Exception e) { _logger.Error(e.Message); } }
public void Run() { var cars = new List <Car> { new Car("BMV", 50000), new Car("Opel", 20000), new Car("Nissan", 40000) }; var binarySerialization = new BinarySerialization("cars.bin", cars.GetType()); var xmlSerialization = new XMLSerialization("cars.xml", cars.GetType()); var jsonSerialization = new JSONSerialization("cars.txt", cars.GetType()); binarySerialization.Serialize(cars); xmlSerialization.Serialize(cars); jsonSerialization.Serialize(cars); var carsFromBinary = (List <Car>)binarySerialization.Deserialize(); var carsFromXML = (List <Car>)xmlSerialization.Deserialize(); var carsFromJSON = (List <Car>)jsonSerialization.Deserialize(); }