-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatic.cs
44 lines (36 loc) · 1.24 KB
/
Static.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
using System.IO;
using System.Xml.Serialization;
namespace Weather_Images_Downloader
{
static class Static
{
public static Settings SettingsInstance { get; set; }
static Static()
{
SettingsInstance = new Settings();
}
public static void SaveSettings()
{
using (var fs = new FileStream("weathersettings.xml", FileMode.Create))
{
var serializer = new XmlSerializer(typeof(Settings));
serializer.Serialize(fs, SettingsInstance);
}
}
public static void LoadSettings()
{
if (!File.Exists("weathersettings.xml")) return;
Settings settings;
using (var fs = new FileStream("weathersettings.xml", FileMode.Open))
{
var serializer = new XmlSerializer(typeof (Settings));
settings = serializer.Deserialize(fs) as Settings;
}
var properties = SettingsInstance.GetType().GetProperties();
foreach (var property in properties)
{
SettingsInstance.GetType().GetProperty(property.Name).SetValue(SettingsInstance, property.GetValue(settings));
}
}
}
}