37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System.Xml;
|
|||
|
|
using System.Xml.Serialization;
|
|||
|
|
|
|||
|
|
namespace MetroGauges.General
|
|||
|
|
{
|
|||
|
|
public class Loader
|
|||
|
|
{
|
|||
|
|
public XmlDataModel Load(string fileName)
|
|||
|
|
{
|
|||
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(XmlDataModel));
|
|||
|
|
|
|||
|
|
using (FileStream fileStream = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
|
|||
|
|
{
|
|||
|
|
using (NamespaceIgnorantXmlTextReader objXmlReader = new NamespaceIgnorantXmlTextReader(fileStream))
|
|||
|
|
{
|
|||
|
|
return (XmlDataModel)xmlSerializer.Deserialize(objXmlReader);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public class NamespaceIgnorantXmlTextReader : XmlTextReader
|
|||
|
|
{
|
|||
|
|
public NamespaceIgnorantXmlTextReader(Stream reader) : base(reader) { }
|
|||
|
|
|
|||
|
|
public override string NamespaceURI
|
|||
|
|
{
|
|||
|
|
get { return string.Empty; }
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|