-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.cs
53 lines (41 loc) · 1.45 KB
/
Settings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BoardGameChooser
{
[Serializable]
public class Settings
{
public List<BoardGame> BoardGames { get; set; }
public Random rand = new Random();
public Settings()
{
this.BoardGames = new List<BoardGameChooser.BoardGame>();
}
public Settings(string FileName)
: this()
{
try
{
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(this.GetType());
System.IO.StringReader read = new System.IO.StringReader(System.IO.File.ReadAllText(FileName));
Settings setting = serializer.Deserialize(read) as Settings;
this.BoardGames = setting.BoardGames;
}
catch (Exception exc)
{
System.Windows.Forms.MessageBox.Show(exc.Message);
}
}
public override string ToString()
{
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(this.GetType());
StringBuilder retval = new StringBuilder("");
System.IO.StringWriter s = new System.IO.StringWriter(retval);
serializer.Serialize(s, this);
return retval.ToString();
}
}
}