我使用下面的代码来序列化拓扑类到xml:
public static bool WriteTopologyFile(string path)
{
try
{
XmlSerializer serializer = new XmlSerializer(typeof(Topology));
using (StreamWriter reader = new StreamWriter(path))
{
serializer.Serialize(reader, Runtime.Topology);
}
return true;
}
catch (Exception ex)
{
Log.WriteEventLog(ex, EventLogEntryType.Error);
}
return false;
}
在拓扑类中,有一些DateTime字段,我想在
中序列化这些DateTime字段System.Xml.XmlDateTimeSerializationMode.RoundtripKind
模式。我怎么能做到呢?
[XmlIgnore]
public DateTime Time { get; set; }
[XmlElement("Time")]
public string strTime
{
get { return Time.ToString("o"); }
set { Time = DateTime.Parse(value); }
}