-
Notifications
You must be signed in to change notification settings - Fork 1
/
Xml.cs
65 lines (63 loc) · 1.33 KB
/
Xml.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
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace Xml
{
public static class Xml
{
public static void Save(String Path, System.Object Value, Type Type)
{
try
{
if (System.IO.File.Exists(Path))
System.IO.File.Delete(Path);
System.IO.FileStream FileStream = new System.IO.FileStream(Path, System.IO.FileMode.OpenOrCreate);
try
{
XmlSerializer XmlSerializer = new XmlSerializer(Type);
XmlSerializer.Serialize(FileStream, Value);
}
catch (Exception e)
{
}
FileStream.Close();
FileStream.Dispose();
}
catch
{
}
}
public static System.Object Load(String Path, Type Type)
{
System.Object Result = Activator.CreateInstance(Type);
try
{
String Dir = System.IO.Path.GetDirectoryName(Path);
if (!Directory.Exists(Dir))
Directory.CreateDirectory(Dir);
System.IO.FileStream FileStream = new System.IO.FileStream(Path, System.IO.FileMode.OpenOrCreate);
try
{
XmlSerializer XmlSerializer = new XmlSerializer(Type);
Result = XmlSerializer.Deserialize(FileStream);
}
catch (Exception e)
{
return null;
}
finally
{
FileStream.Close();
FileStream.Dispose();
}
}
catch
{
}
return Result;
}
}
}