我必须以“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 中序列化时间?