使用 Microsoft Bond 的 C# DateTime 序列化

C# DateTime Serialization with Microsoft Bond

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

我正在切换简单的 类 和邦德女士的属性,一切正常,直到我得到一个带有 DateTime 的属性。 然后我在序列化过程中遇到 Dictionary KeyNotFound Exception 错误。

我怀疑邦德不支持日期时间,是吗? 如果是,为什么没有实施? DateTime 不是基本类型,但添加自定义转换器是不值得的,与 protobuf-net 相比速度增益很小,我不需要泛型,只是简单快速 de/serializer.

我希望我遗漏了什么,我真的很想使用 Bond,但我也需要一个简单的工具,我不能冒险破坏应用程序,因为默认情况下不支持 Date 或 Guid 等基本功能。 经过数小时的研究,我在这里写下了 C# bond 的年轻指南,但没有明确提及支持和不支持的内容。

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

对于 GUID,有 Bond.GUID,其中有 implicit conversions to/from System.Guid. Note that Bond.GUID lives in bond.bond, so if you want to refer to this from a .bond file, you'll need to use Bond's import functionalityimport "bond/core/bond.bond"

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

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

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

附带说明一下,根据我的经验,与 DateTime 相比,DateTimeOffset 是一种更普遍有用的类型。