开发者

Easiest way to serialize and store objects in c#?

开发者 https://www.devze.com 2023-03-20 15:26 出处:网络
Im looking for a simple solution to serialize and store objects that contain configuration, applicatio开发者_开发技巧n state and data. Its a simple application, its not alot of data. Speed is no issue

Im looking for a simple solution to serialize and store objects that contain configuration, applicatio开发者_开发技巧n state and data. Its a simple application, its not alot of data. Speed is no issue. I want it to be in-process. I want it to be more easy-to-edit in a texteditor than xml.

I cant find any document database for .net that can handle it in-process. Simply serializing to xml Im not sure I want to do because its... xml. Serializing to JSON seems very javascript specific, and I wont use this data in javascript.

I figure there's very neat ways to do this, but atm im leaning to using JSON despite its javascript inclenation.


Just because "JSON" it's an acronym for JavaScript Object Notation, has no relevance on if it fits your needs or not as a data format. JSON is lightweight, text based, easily human readable / editable and it's a language agnostic format despite the name.

I'd definitely lean toward using it, as it sounds pretty ideal for your situation.


I will give a couple of choices :

  1. Binary serialization: depends on content of your objects, if you have complicated dependecy tree it can create a problems on serializing. Also it's not very flexible, as standart binary serialization provided by Microsoft stores saving type information too. That means if you save a type in binary file, and after one month decide to reorganize your code and let's say move the same class to another namespace, on desirialization from binary file previously saved it will fail, as the type is not more the same. There are several workarrounds on that, but I personally try to avoid that kind of serialization as much as I can.

  2. ORM mapping and storing it into small database. SQLite is awesome choice for this kind of stuff as it small (single file) and full ACID support database. You need a mapper, or you need implement mapper by yourself.

I'm sure that you will get some other choice from the folks in a couple of minutes.

So choice is up to you.

Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消