RoundtripKind模式xml序列化

本文关键字:序列化 xml 模式 RoundtripKind | 更新日期: 2023-09-27 18:14:56

我使用下面的代码来序列化拓扑类到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

模式。我怎么能做到呢?

RoundtripKind模式xml序列化

[XmlIgnore]
public DateTime Time { get; set; }
[XmlElement("Time")]
public string strTime
{
        get { return Time.ToString("o"); }
        set { Time = DateTime.Parse(value); }
}
相关文章: