XMLSerializer 未序列化 DateTime [英] XMLSerializer not serializing DateTime
本文介绍了XMLSerializer 未序列化 DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
输入...请注意,注释是从 xsd 工具生成的代码.它在一个 31,834 行的文件中并且是专有的,但我在这里给出了一个粗略的近似值.
Input...note that comment is generated code from the xsd tool. It's in a 31,834 line file and proprietary, but I put a rough approximation in here.
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.1432")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public class comment
{
private System.DateTime commentDateField;
private bool commentDateFieldSpecified;
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public System.DateTime commentDate
{
get
{
return this.commentDateField;
}
set
{
this.commentDateField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool commentDateSpecified
{
get
{
return this.commentDateFieldSpecified;
}
set
{
this.commentDateFieldSpecified = value;
}
}
//other fields omitted for clarity
}
comment c = new comment();
c.text = txtComment.Text;
c.commentDate = DateTime.Now;
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
XmlSerializer xs = new XmlSerializer(typeof(comment));
xs.serialize(sw as TextWriter, c);
string output = sb.ToString();
输出->
<comment>
<text>My Comment Text</text>
</comment>
日期在哪里?
推荐答案
Pavel 的评论是正确答案.
Pavel's comment was the correct answer.
另外,你说省略了其他字段为了清楚起见".是否有偶然的机会,命名的字段或属性commentDate 在其中指定字段?
Also, you say "omitted other fields for clarity". Is there, by chance, a field or property named commentDateSpecified among those fields?
这篇关于XMLSerializer 未序列化 DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文