private void SerializeToFile(HighScores highScores, string path)
 {
     using (FileStream stream = File.Create(path))
     {
         XmlSerializer serializer = new XmlSerializer(typeof(HighScores));
         serializer.Serialize(stream, highScores);
     }
 }
示例#2
0
        public void TestPlayerXML()
        {
            HighScores high = new HighScores();
            Player player = new Player();
            XML xml = new XML();
            player.alive = false;
            player.onWallRight = true;
            xml.Player = player;

            Assert.Equals(xml.Player.alive, player.alive);
            Assert.Equals(xml.Player.onWallRight, player.onWallRight);
        }
        private string SerializeToString(HighScores highScores)
        {
            var stringBuilder = new StringBuilder();

            using (TextWriter stream = new StringWriter(stringBuilder))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(HighScores));
                serializer.Serialize(stream, highScores);
            }

            return stringBuilder.ToString();
        }
示例#4
0
        public void TestHighScoreXML()
        {
            HighScores high = new HighScores();
            Player player = new Player();
            XML xml= new XML();

            high.Name1 = "PLayer 1";
            high.Name2 = "PLayer 2";

            high.Score1 = long.MaxValue;
            high.Score2 = long.MinValue;

            xml.HighScores = high;
            Assert.AreEqual(xml.HighScores.Name1, high.Name1);
            Assert.AreEqual(xml.HighScores.Name2, high.Name2);
            Assert.AreEqual(xml.HighScores.Score1, high.Score1);
            Assert.AreEqual(xml.HighScores.Score2, high.Score2);

            Assert.AreEqual(xml.HighScores.Name, high.Name);
            Assert.AreEqual(xml.HighScores.Score, high.Score);

            Assert.AreEqual(xml.HighScores.nice1, high.nice1);
            Assert.AreEqual(xml.HighScores.nice2, high.nice2);
        }
示例#5
0
 private void SerializeH(HighScores value)
 {
     Console.WriteLine(value.Score);
     if (dank)
     { Console.WriteLine("This was avoided " + value.Score);
         dank = false;
         return;
     }
     dank = true;
     Console.WriteLine(value.Score);
      TextWriter writer = new StreamWriter(Directory.GetCurrentDirectory().ToString() + "\\Highscores.xml");
      serH.Serialize(writer, value);
      writer.Close();
 }
 public Task<string> AsyncSerializeToString(HighScores highScores)
 {
     return Task.Run(() => SerializeToString(highScores));
 }
 public async void AsyncSerializeToFile(HighScores highScores, string path)
 {
     await Task.Run(() => SerializeToFile(highScores, path));
 }