2

我在 C# 项目和 Script# 之间有很多共享的业务逻辑代码。

自从 script# 核心库发生重大变化(当 DateTime 类变为 Date 时),事情就向南了。

有没有人想出通用的防弹解决方案如何处理它?我读到有人说他们写了一个包装器,但没有人显示他们的来源。可能会有一些陷阱,比如 JS Date 从 0 开始计算月份,C# DateTime 从 1 开始计算等等,所以它并不是一个简单的包装器......

分叉原始脚本#并将 Date 重命名回 DateTime 并不是一个真正的选择,因为那时你需要处理两个项目 - 你的和 fork。

参考:

PS我知道#ifdef解决方案,请不要建议它;)

4

1 回答 1

0

One potential approach is to store just the tick count as a long within your data model. Then use a set of helpers that interpret the ticks as a date/datetime and provide the APIs you're looking for. Just a thought... given the semantic differences, some wrapper/abstraction is anyway required for those who want to share code, and this is one approach for building that.

One side-benefit to this approach is serialization to/from json is simplified ... a) since there is no date literal syntax in JSON, and b) because the precision of ticks is different across script and .net ... so at the least if you use the .net tick count and it is not updated on the client, it just roundtrips without loosing precision.

If you do build this, this would be interesting to share back to the community.

于 2012-08-19T17:48:34.320 回答