I am using the .NET Compact Framework 3.5 and I am trying to determine if there is a standard way to store settings that a user to change in my application. I am aware of the Compact 3.5 SQL database, but I am trying to avoid that if I can to avoid a dependency that is not already installed on the us开发者_JAVA百科er’s mobile device (I already have to worry about the 3.5 .NET Framework so I am trying to avoid any other dependencies if I can).
I saw that the old .config file (via System.Configuration.ConfigurationSettings.AppSettings) is obsolete and doesn’t appear to be supported on the Compact framework anyway.
Aside from stuffing it in an xml file stored in /Application Data/My App/ and parsing it, are there any built in libraries for this type of functionality?
I am not seeing much online or on this site about this. Mostly non-compact framework solutions.
I actually ended up using System.Xml.Serialization.XmlSerializer. This allowed us to store and restore settings with little effort. It is tolerant of changes to the settings when doing an upgrade/downgrade.
OpenNetCF has support for loading and saving settings to an xml file
OpenNetCF.AppSettings namespace, and the SettingsFile class should do the trick :)
I use the registry for many settings in my application. We created a wrapper around registry calls that handle exceptions, memory cleanup, etc. After that, it works pretty well. I guess that all depends on what kind of settings you are talking about.
After testing OpenNetCF.AppSettings and trying to create a configuration manager from scratch, I ended up using this class. It's simple, and it just work.
Edit: the link above is dead, so I put the class source code here.
Usage:
ConfigurationManager.AppSettings["YourSetting"]
ConfigurationManager.AppSettings["YourSetting"] = "test";
Another fallback option is good old fashioned .INI files. There's a number of pure C# classes out there for parsing them and using the values. Simple and straightforward.
精彩评论