XmlSerializer,仅将时间反序列化为DateTime类型

发布于 2024-10-07 13:35:50 字数 258 浏览 0 评论 0原文

我的 WCF 使用 XmlSerializer 来序列化和反序列化相当复杂的对象。问题是,DateTime 属性之一的相应 XML 负载值可以指定为 xs:date、xs:time 或 xs:dateTime 值。我注意到,当在输入 XML 中指定仅时间值(例如 16:55:00Z)时,当前日期在反序列化期间会被“前置”(例如 2010-12-13T16:55:00Z)。这显然会创建错误数据,我宁愿选择 DateTime.MinValue。 有什么方法可以控制这种行为吗?

提前致谢

My WCF uses XmlSerializer to serialize and deserialize fairly complex objects. Problem is, the corresponding XML payload value of one of the DateTime properties could be specified as either xs:date, xs:time or xs:dateTime values. I've noticed that when a time-only value (e.g. 16:55:00Z) is specified in the input XML the current date gets 'prepended' during deserialization (e.g. 2010-12-13T16:55:00Z). This obviously creates false data, I would rather have preferred DateTime.MinValue.
Is there a way I can control this behavior?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方的巷 2024-10-14 13:35:50

我们使用 WCFDate 将日期部分作为 xs:date 发送。

请参阅http://www.codeproject.com/Articles/182960/ WCF-Support-for-xs-date 代码。

We use WCFDate to send the date part as xs:date.

See http://www.codeproject.com/Articles/182960/WCF-Support-for-xs-date for code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文