///
/// 實體類序列化為Xml
///
///
public void SerializeXml(List
{
XmlSerializer serializer = new XmlSerializer(typeof(List
using (StringWriter textWriter = new StringWriter())
{
serializer.Serialize(textWriter, slave);
string xmlContent = textWriter.ToString();
// 這裡可以將xmlContent儲存到檔案
}
}
///
/// Xml反序列化為實體類
///
///
///
///
public List
{
// 獲取應用程式根目錄下的XML檔案路徑
string xmlFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, xmlName);
// 建立XmlSerializer物件
XmlSerializer serializer = new XmlSerializer(typeof(List
// 反序列化XML檔案到List
using (StreamReader reader = new StreamReader(xmlFilePath))
{
return (List
}
}