简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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