How do I expose a TimeSpan through a WCF Data Service?

无人久伴 提交于 2019-12-01 06:13:09

I would suggest exposing a new property for serialization (marked with the DataMemberAttribute) that use the Ticks property of your original timespan.

For example:

[DataMember("TheTimeSpanTicks")]
public long TheTimeSpanTicks
{
    get { return TheTimeSpan.Ticks; }
    set { TheTimeSpan = new TimeSpan(value); }
} 

I'm not sure what the accessor requirements for serialization will be. Maybe you could use protected instead of public.

You could expose the duration as Ticks, TotalSeconds, or some other primitive that can be calc'ed to hours, minutes, etc?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!