使用Microsoft Bond进行C#DateTime序列化

时间:2017-02-25 21:20:37

标签: bond

我正在将我的应用程序中的内部序列化从Jil替换为Bond

我正在使用Ms Bond属性切换简单的类,一切正常,直到我得到一个 DateTime 。 我在序列化期间遇到了 Dictionary KeyNotFound Exception 错误。

我怀疑邦德不支持DateTime,是这样吗? 如果是,为什么没有实施? DateTime不是基本类型,但添加自定义转换器是不值得的,速度增益vs protobuf-net是最小的,我不需要泛型,只需简单的快速/序列化。

我希望我遗漏了一些东西,我真的想要使用Bond,但我也需要一个简单的工具,我不能冒险破坏应用程序,因为默认情况下不支持像Date或Guid这样基本的东西。 经过数小时的研究后,我正在写这篇文章,C#bond的年轻指南没有明确提到什么是不支持的。

1 个答案:

答案 0 :(得分:1)

不,Bond中没有内置时间戳类型。 Bond中的内置类型记录在manual for the gbc compiler

对于GUID,System.Guidimplicit conversions到/ Bond.GUID。请注意,import "bond/core/bond.bond"位于bond.bond中,因此如果您想从.bond文件中引用此内容,则需要use Bond's import functionalityboost::posix_time::ptime

有一个示例显示如何使用DateTime with a custom type alias

Bond中没有内置时间戳类型的原因是有很多不同的方式(和标准)来表示时间戳。有一个类似的C++ example表示用DateTime表示时间,突出显示表示时间的各种不同方式。

我们的经验是,项目通常已经有了他们想要使用的时间戳的表示,因此,我们建议您使用转换器,以便您可以使用适合您情况的表示。

作为旁注,我的经验是,与*,html,body{ margin: 0;/*her is the trick*/ padding: 0;/*her is the trick*/ } body,html{ height: 100%; background-color: #f06d06; font-family: robotoregular; } .parent{ width:300px; height:100px; background-color:#eee; position:relative;/* for the demo*/ } .child{ position : absolute;/*for the demo*/ bottom:0px;/* for the demo*/ top: 50%;/* for the demo*/ transform: translate(0, -50%);/* for the demo*/ width:100vw;/* Her is the trick !*/ height:50px; background-color:red; }相比,DateTimeOffset是一种更常用的类型。