|
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace Sedge.Core.FileSystemWrap
{
class XmlFileSerializer : IXmlFileSerializer
{
public object Load(string path, Type type)
{
object result;
try
{
using (FileStream fs = new FileStream(path, FileMode.Open))
{
XmlSerializer xs = new XmlSerializer(type);
result = xs.Deserialize(fs);
}
}
catch
{
result = null;
}
return result;
}
public bool Save<T>(string path, T obj)
{
bool result = true;
try
{
using (FileStream fs = new FileStream(path, FileMode.Create))
{
XmlSerializer xs = new XmlSerializer(typeof(T));
using (XmlTextWriter writer = new XmlTextWriter(fs, Encoding.Unicode))
{
writer.Formatting = Formatting.Indented;
xs.Serialize(writer, obj);
}
}
}
catch
{
result = false;
}
return result;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a software developer from Toronto with 15 years of experience in software design and development. My major professional area is the development of highly customized software solutions, including desktop and web applications. Industrial process automation and hardware-related software development are among my favorite projects and I enjoyed developing several applications for semiconductor manufacturing companies.
My blog: http://LunarFrog.com/blog