コード例 #1
0
        public void UnitRdz_Serialization()
        {
            string fileName = "DaryScores.bin";
            var    p1       = new PlayerDary();

            p1.Add(new Player("GG", "Floyd"), 11);
            p1.Add(new Player(null, "Betty"), 22);
            p1.Add(new Player(null, "Alvin"), 33);
            p1.Add(new Player("GG", "Chuck"), 44);
            p1.Add(new Player("A1", "Ziggy"), 55);
            p1.Add(new Player("GG", null), 66);

            IFormatter formatter = new BinaryFormatter();

            using (var fs = new FileStream(fileName, FileMode.Create))
            { formatter.Serialize(fs, p1); }

            PlayerDary p2 = null;

            using (var fs = new FileStream(fileName, FileMode.Open))
            { p2 = (PlayerDary)formatter.Deserialize(fs); }

            Assert.AreEqual(6, p2.Count);
        }
コード例 #2
0
        public void CrashRdz_NullCB()
        {
            var dary = new PlayerDary((SerializationInfo)null, new StreamingContext());

            ((IDeserializationCallback)dary).OnDeserialization(null);
        }
コード例 #3
0
        public void CrashRdz_ArgumentNull()
        {
            var dary = new PlayerDary();

            ((ISerializable)dary).GetObjectData(null, new StreamingContext());
        }