This article is a mirror article of machine translation, please click here to jump to the original article.

View: 28031|Reply: 3

[Communication] .net/c# ini configuration file parsing tool

[Copy link]
Posted on 10/30/2017 11:52:00 AM | | | |


Because the program needs a configuration file, the configuration file can be created with VS, and then add the appSettings node, the value of my configuration file contains some special symbols, such as: < > These special symbols, will report an error, and it needs to be escaped to be normal

Decisively don't use this thing, because escaping special strings is too troublesome, and there is another way to make the configuration into a json string, but it's also quite troublesome, half of the program configuration files are ini files, and I found a good third-party component "ini-parser"

.NET, Mono, and Unity3d compatible (*) libraries for reading/writing INI data from IO streams, file streams, and strings written in C#.

Merge operations of complete ini files, parts or even subsets of keys contained in files are also implemented.

The library is 100%. .NET code and does not have any dependencies on Windows API calls for easy portability.


First, the nuget command is installed as follows:



Read and load ini configuration file:



Read the configured value:



Update or add new configurations



It's very easy to use, the ini file of the operation, by default is read and added from the root directory of the program, my code is as follows:


The configuration file format is as follows:
[db_config]
SqlType = 123
SqlConn = test











Previous:Difference between Android sdk and ndk
Next:.NET/C# Universal Database Query Tool Helper [with source code]
Posted on 11/2/2017 1:57:47 PM |
What is this for?
 Landlord| Posted on 4/17/2018 10:47:51 PM |
Could not parse file config.ini while parsing line number 0 with value '' - IniParser version: 2.5.2.0




Read the configuration file as above, if the file does not exist, it will throw an exception
 Landlord| Posted on 4/17/2018 10:50:13 PM |


The ini read is an empty file, the node does not exist, and no exception is thrown!



If the ini file is scribbled content, an exception is thrown
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com