开发者

Can c# application settings be serialized in a format besides XML (protobuf-net)?

Can c# application settings be serialized in a format besides XML? I can't find anything which would support the theory that one can. Specifically, the format I'm trying to save in is the protocol buffer format via protobuf-net.

If I can't, and need to write to a save file "by hand", how do I get the path that Visual Studio (2010) is using to save the application settings to? I can get the path

...\AppData\Local\${Compan开发者_C百科y Name}\${Application Name}\

The problem is that Visual Studio is actually saving my application settings to something like

...\AppData\Local\${Company Name}\${Application Name}.exe_Url_uzttbld0ofvuokf2y4ynfn05v334i4tp\

I would like for the my xml settings file and my protobuf-net file to appear in the same location.


(Assuming you are writing WinForms or WPF application. The rules for web apps are different)

You can find the location of the configuration files for your executable through the ExeConfigurationFileMap class. Note though, that your code might not have write access to all of these locations, depending on how the application was installed.

you cannot change the format of the standard configuration file. The classes in the System.Configuration namespace only understand XML configuration files. You will have to write your own serialization/deserialization support for the protobuf-net file, and if you want/need to use the System.Configuration namespace, you will have to synchronize the content of your file with the standard config file.


I wouldn't touch the main config itself, however you can trivially store a path as a setting, i.e.

<fooSettings source="myfile.bin"/>

Then at runtime you could use the regular settings framework to get the file-path, and then deserialize from there.

That should work - although I'm not sure it is the classic use-case; people generally like their configuration settings to be human-readable and editable via notepad.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜