简体   繁体   English

序列化/反序列化-我应该使用不变的区域性信息还是保留当前区域性信息

[英]Serialization\De-serialization - Should I use Invariant culture info or rather persist the current culture info

I came to ask some advice before I plunge headfirst into code. 在我开始沉迷于代码之前,我来问一些建议。

On the application I am working on, I am running into the "," (comma) vs "." 在我正在处理的应用程序上,我遇到了“,”(逗号)与“”。 (dot) discrepancy for a decimal separator. 小数点分隔符的(点)差异。

When I persist to a file, change the regional settings and reopen said file, I am running into exceptions on deserialization. 当我坚持一个文件,更改区域设置并重新打开该文件时,我遇到了反序列化方面的异常。

My question is as follows. 我的问题如下。

If I use invariant culture info everywhere where serialization/deserialization happens, will I run into this problem again? 如果我在发生序列化/反序列化的任何地方都使用不变的区域性信息,是否会再次遇到这个问题? In my mind, this should work everywhere, even if regional settings get changed. 我认为,即使更改了区域设置,此方法也应在任何地方都有效。 Am I correct in assuming this ? 我可以这样假设吗?

Another idea which is not ideal is to associate\\persist a current cultureinfo with a saved file. 另一个不理想的想法是将当前的CultureInfo与保存的文件关联\\持久化。 Not very nice to do. 不太好做。

I would welcome any advice and insight into this issue. 欢迎您对此问题提出任何建议和见识。 If anything is unclear, please feel free to comment. 如果不清楚,请随时发表评论。

Thanks in advance for all your help!! 预先感谢您的所有帮助!

You should use invariant culture anytime you are persisting to a backend. 只要坚持到后端,就应该使用不变文化。 Culture specific formats should only be presented directly to a user. 特定于文化的格式仅应直接呈现给用户。 Data changes between versions of Windows and you will not be protected from exceptions associated with deserialization unless you use standard formats that do not change. Windows版本之间的数据更改,除非您使用不变的标准格式,否则您将不会受到与反序列化相关的异常的保护。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM