无法序列化Timespan值

时间:2013-04-11 19:39:39

标签: c# .net serialization time

我必须以这种格式保留时间“00:00:23.123213”。

所以我尝试使用Timespan

  [Serializable()]
    public class Item
    {
        public TimeSpan Start { get; set; }

但该字段在文件中始终为为空

var test = new ContentItems();
 var item2 = new Item();
            item2.ContentType = ContentTypes.Paragraph;
            item2.Data = "Create a new XmlSerializer instance with the type of the test class.";
            item2.DataType = DataTypes.Text;
            item2.Start = TimeSpan.FromSeconds(6);
            item2.End = TimeSpan.FromSeconds(9);
            test.Items.Add(item2);

            using (var writer = new System.IO.StreamWriter(@"C:\Projects\1.xml"))
            {
                var serializer = new XmlSerializer(typeof(ContentItems));
                serializer.Serialize(writer, test);
                writer.Flush();
            }

我的问题: 哪种类型更适合在.NET中序列化时间?

0 个答案:

没有答案