-
Notifications
You must be signed in to change notification settings - Fork 1
/
SimpleXmlDeserializator.cs
executable file
·41 lines (35 loc) · 1.09 KB
/
SimpleXmlDeserializator.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
using System;
using System.IO;
using System.Xml.Serialization;
namespace XmlUtils
{
/// <summary>
/// Use:
///
/// SimpleXmlDeserializator sertalizator = new SimpleXmlDeserializator();
///
/// rootAreas = sertalizator.DeserializeFile<RootAreas>(CrawlerConfig.GetConfigData.TargetFolder + "AREAS.xml");
///
/// </summary>
public class SimpleXmlDeserializator
{
public T Deserialize<T>(String strXMLAreas)
{
T ret;
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (StringReader rdr = new StringReader(strXMLAreas))
{
ret = (T)serializer.Deserialize(rdr);
}
serializer = null;
return ret;
}
public T DeserializeFile<T>(String strXMLFileName)
{
string strXMLAreas = File.ReadAllText(strXMLFileName, System.Text.Encoding.UTF8);
T ret = Deserialize<T>(strXMLAreas);
strXMLAreas = null;
return ret;
}
}
}