-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestStorage.cs
43 lines (40 loc) · 1.09 KB
/
TestStorage.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
using System;
using System.IO;
using System.Xml.Serialization;
namespace Wpf_ManageStudents
{
internal class TestStorage
{
internal static void WriteXml<T>(T students, string fileName)
{
try
{
XmlSerializer serializer=new XmlSerializer(typeof(T));
FileStream stream;
stream = new FileStream(fileName, FileMode.Create);
serializer.Serialize(stream, students);
stream.Close();
}
catch (Exception x)
{
Console.WriteLine(x);
throw;
}
}
internal static T ReadXml<T>(string fileName)
{
try
{
using (StreamReader sr = new StreamReader(fileName))
{
XmlSerializer xmlSer = new XmlSerializer(typeof(T));
return (T)xmlSer.Deserialize(sr);
}
}
catch (Exception)
{
return default(T);
}
}
}
}