Ejemplo n.º 1
0
        public CZoo DeserializeZoo()
        {
            FileStream stream = new FileStream(this._filename, FileMode.Open);

            BinaryFormatter bf = new BinaryFormatter();

            CZoo ds = (CZoo)bf.Deserialize(stream);

            stream.Close();

            return(ds);
        }
        public static void TestWithClasses()
        {
            Console.WriteLine("##### TESTING WITH CLASSES #####\n");


            CCow  cow  = new CCow("Marguerite");
            CLion lion = new CLion("Mufasa");

            CSnake  snake  = new CSnake("Kaa");
            CLizard lizard = new CLizard("Rango");

            CPlatypus platypus = new CPlatypus("Perry");


            cow.Eat("grass");
            cow.Move();
            cow.Lactate();

            LineBreak();

            lion.Eat("meat");
            lion.Move();
            lion.Lactate();

            LineBreak();

            snake.Eat("small animals");
            snake.Move();
            snake.LayEggs();

            LineBreak();

            lizard.Eat("insects");
            lizard.Move();
            lizard.LayEggs();

            LineBreak();

            platypus.Eat("insects");
            platypus.Move();
            platypus.Lactate();
            platypus.LayEggs();

            LineBreak();

            Console.WriteLine("# CREATING ZOO ...");
            CZoo zoo = new CZoo();

            zoo.AddAnimal(cow);
            zoo.AddAnimal(lion);
            zoo.AddAnimal(snake);
            zoo.AddAnimal(lizard);
            zoo.AddAnimal(platypus);

            LineBreak();

            zoo.MakeAllEat();

            LineBreak();

            zoo.MakeAllWalk();

            Console.WriteLine("# SERIALIZING ...");
            zoo.SerializeZoo();

            Console.WriteLine("# CREATING NEW ZOO FROM SERIALIZED ZOO ...");
            CZoo newZoo = zoo.DeserializeZoo();

            LineBreak();

            Console.WriteLine("# TESTING NEW ZOO :");
            newZoo.MakeAllEat();

            Console.WriteLine("\n\n");
        }