开发者

Can I save an object to the app.config file?

开发者 https://www.devze.com 2023-01-29 23:21 出处:网络
I need to use a config file for my application which will save a list of details for e开发者_StackOverflow社区ach entity:

I need to use a config file for my application which will save a list of details for e开发者_StackOverflow社区ach entity: for example-

<person A>
         <name= >
         <age= >
<person B>
         <name=>
         <age= >

is something of this sort possile in the settings class or this requires using the app.config file wihtout the settings class wrapper?

Edit: My application used to have a single entity, now it should support multiple entities and therefore save multiple entities in some config.


Yes, you can save any sort of information (strings) in .config file. You'd then use the ConfigurationManager class to access the saved information by using a Key.

But why would you want to save information like this in the .config?

I recommend you use an XML document for this purpose. You can then use the XDocument class to parse it.

Edit:

After reading your comment, I think the app.config file cannot save an object. So you could not save a class object there.


The config file is not a good place to store dynamic configuration information, it's intended for configuring an app, not maintaining state.

Rather use a separate file, or something like a SQLite database to store dynamic data.


Well, you could use Serialization for this purpose. But I still don't see the point of storing it in the .config file. Anyway, you could serialize the object in a XML format and store it in a key that you would add to the .config file, as a string. I guess that would solve it.

If you decide to store it as a simple XML file, use the XMLDocument and XMLNode classes.

0

精彩评论

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

关注公众号