예제 #1
0
        public void testSerializeObjectWithList()
        {
            List <Cat> list = new List <Cat>()
            {
                new Cat()
                {
                    name = "Tom"
                },
                new Cat()
                {
                    name = "BlueCat"
                },
                new Cat()
                {
                    name = "BlackCatPolice"
                }
            };
            CatHome home = new CatHome();

            home.Initialize(list);

            FileStream      fs = new FileStream("object_with_list", FileMode.Create);
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(fs, home);
            fs.Close();
        }
예제 #2
0
        public void testDeSerializeObjectWithList()
        {
            FileStream      fs   = new FileStream("object_with_list", FileMode.Open);
            BinaryFormatter bf   = new BinaryFormatter();
            CatHome         home = (CatHome)bf.Deserialize(fs);

            fs.Close();

            Assert.AreEqual(home.List[0].name, "Tom");
            Assert.AreEqual(home.List[1].name, "BlueCat");
            Assert.AreEqual(home.List[2].name, "BlackCatPolice");
        }