序列化复杂类型System.Nullable<&System.DateTime的GT; [英] Serialize Complex Type System.Nullable<System.DateTime>

查看:287
本文介绍了序列化复杂类型System.Nullable<&System.DateTime的GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要序列日期时间,这样,当日期时间为空我不明白标签本身。

I want to serialize DateTime so that when DateTime is null I dont get the tag itself.

我也为上述集布尔规定,但我的问题是日期时间是值类型的它永远不会为空,因此指定的布尔将永远是真的。

I have also set bool specified for the above but my problem is DateTime being of value type it will never be null hence the bool specified will always be true for it.

我甚至尝试更换日期时间为System.Nullable但我得到序列化错误时,发送请求或接收来自web服务的响应。

I even tried replacing DateTime to System.Nullable but I get Serialization Error when Sending request or receiving response from WebService.

有什么办法呢?

推荐答案

请参见这个问题,其中马克给出了一个很好的答案。只需添加一个 ShouldSerializeMyDateTime 方法类:

See this question, where Marc gives an excellent answer. Just add a ShouldSerializeMyDateTime method to your class :

public bool ShouldSerializeMyDateTime()
{
    return MyDateTime.HasValue;
}



显然,这是XML序列化的无证功能...您还可以使用一个名为 MyDateTimeSpecified

这篇关于序列化复杂类型System.Nullable<&System.DateTime的GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆