First, the introduction
For developers of NCF (NET Compact Edition), there are generally only two ways to save application options:
1. Write the value of the option to the registry, but if all applications write a large number of values to the registry it will eventually result in the registry consuming system resources and affecting the efficiency of the system, and this is why many software have to be reinstalled after the device is rebooted. This practice is not recommended in accordance with the idea of "procedure as independent as possible" in the context of modern procedure writing.
2, the option value as an initialization file to save, so that you can maximize the avoidance of system resource consumption, improve the independence of the program operation, this practice is personally considered preferable scheme. And this approach is very simple in the. NET full edition and can be implemented directly with XML serialization classes. However, in the Net Compact Edition tailored for smart mobile devices, saving and using program options becomes depressing because the XML serialization attribute is not provided. Program developers have to write/read the file encoding for each program option, and this tedious step is never an interesting thing.
Second, functional overview
In this article, I'll build a class that automates the save/Read and write of initialization files with the reflection capabilities of. Net. In this class, as long as the author of the program defines the internal member variables of the class within the class by the name of the program option (as this step still requires the programmer to do the manual coding within the class), so this class is called a semi-automatic initialization class, and this class automatically saves/reads the program option from the initialization file, Programmers no longer have to do the tedious coding of the read and write file portions. Also, the build of this class can have a benefit: because the application's options are stored inside the class as member variables, programmers can query the options for initializing files by using the function of the automatically listing variable members provided by VS. For example, write String Myappname= tobjAPPOption.General.APPName. As far as I know, it's not fun to remember the exact characters of a lot of program options Oh 8-)