class Common

{
///
/// 将XML文件写入指定的对象
///
/// "xmlFile">
xml绝对路径
/// "type">
序列的类型,要与XML对应的类
/// 将对象返回,当文件操作失败则返回Null值
public static object DeserializeXmlToObject(
string xmlFile, Type type)

{

XmlSerializer mySerializer =
new XmlSerializer(type);
using (FileStream stream =
new FileStream(xmlFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))

{
return mySerializer.Deserialize(stream);

}

}
///
/// 将对象写入到XML中
///
/// "obj">
数据源对象
/// "xmlFile">
目标路径
/// "type">
转换类型
public static void SerializeObjectToXml(
object obj, String xmlFile, Type type)

{

XmlSerializer mySerializer =
new XmlSerializer(type);
using (FileStream stream =
new FileStream(xmlFile, FileMode.Create, FileAccess.Write, FileShare.Read))

{

mySerializer.Serialize(stream, obj);

}

}

}