0

我正在使用下面的代码将拓扑类序列化为 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;
}

在 Topology 类中,有一些 DateTime 字段,我想将这些 DateTime 字段序列化

System.Xml.XmlDateTimeSerializationMode.RoundtripKind

模式。我怎样才能做到这一点?

4

1 回答 1

0
[XmlIgnore]
public DateTime Time { get; set; }

[XmlElement("Time")]
public string strTime
{
        get { return Time.ToString("o"); }
        set { Time = DateTime.Parse(value); }
}
于 2013-05-28T08:20:16.347 回答