Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Predator tiger = new Predator("Africa", "Tiger", 15);
            Predator Lion  = new Predator("Africa", "Lion", 10);
            Predator Wolf  = new Predator("Europe", "Wolf", 2);

            Animals[] animals = new Animals[] { tiger, Lion, Wolf };
            foreach (object a in animals)
            {
                //Console.WriteLine(a.ToString);
            }
            BinarySerialize(tiger);
            BinaryDeserialize();
            JsonSerialize(Lion);
            JsonDeserialize();
            SOAPSerialize(Wolf);
            SOAPDeserialize();
            XMLSerialize(tiger);
            XMLDeserialize();
            //Array_JsonSerialize(animals);
            //Array_JsonDeserialize();
            Array_XMLSerialize(animals);
            //Array_XMLDeserialize();
            XPath();
            XmlLinq();
        }
Exemplo n.º 2
0
        static void BinaryDeserialize()
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream fs = new FileStream("animals.dat", FileMode.OpenOrCreate))
            {
                Predator newpredator = (Predator)formatter.Deserialize(fs);
                Console.WriteLine($"{newpredator.predator}\n Название :  {newpredator.name } Место обитания : {newpredator.Habitat} Возраст: {newpredator.age} ");
                Console.WriteLine("Объект десериализован binary");
            }
        }
Exemplo n.º 3
0
        static void XMLDeserialize()
        {
            XmlSerializer deserialize = new XmlSerializer(typeof(Predator));

            using (FileStream fs = new FileStream("predator.xml", FileMode.OpenOrCreate))
            {
                Predator predator = (Predator)deserialize.Deserialize(fs);
                predator.Show();
                Console.WriteLine("XML десериализован");
            }
        }
Exemplo n.º 4
0
        static void SOAPDeserialize()
        {
            SoapFormatter formatter = new SoapFormatter();

            using (FileStream fs = new FileStream("predator.soap", FileMode.OpenOrCreate))
            {
                Predator predators = (Predator)formatter.Deserialize(fs);
                Console.WriteLine("Десериализован SOAP");
                predators.Show();
            }
        }
Exemplo n.º 5
0
        static void JsonDeserialize()
        {
            DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(Predator));

            using (FileStream fs = new FileStream("predator.json", FileMode.OpenOrCreate))
            {
                Predator predator = (Predator)json.ReadObject(fs);

                predator.Show();
                Console.WriteLine("Объект десериализован Json");
            }
        }