我想序列化 DatetimeFormatInfo 类型的对象。
我尝试了以下代码:
DateTimeFormatInfo dateTimeFormat = new DateTimeFormatInfo();
dateTimeFormat.ShortDatePattern = "dd-MMM-yy";
xs = new XmlSerializer(dateTimeFormat.GetType());
StreamWriter sw = new StreamWriter("Setting.xml");
xs.Serialize(sw, dateTimeFormat);
但它会引发以下异常。
System.InvalidOperationException未处理。
生成 XML 文档时出错。
类型System.Globalization.GregorianCalendar不是预期的。
使用XmlInclude或SoapInclude属性指定静态未知的类型。
我需要添加什么来序列化 DateTimeFormatInfo 吗?