66.5 My application requires a simple ini file. Is there a easy way to implement this without using any parsing |
|
Yes. This may not be the most efficient way to read from a ini file but it is a pretty good solution that is easy to maintain. You can use a XML file to store your settings. Use a DataSet to read from it. Consider a simple sample file, config.ini. It has three parameters base_path, update_path and output_file. These will map to columns in the settings datatable.
|
| // add error handling |
| DataSet ds = new DataSet(); |
| ds.ReadXml("config.ini", XmlReadMode.Auto); |
| |
| DataTable table = ds.Tables["settings"]; |
| DataRow row = table.Rows[0]; |
| |
| string baseFolder = (string)row["base_path"]; |
| string updateFolder = (string)row["update_path"]; |
| string outputFileName = (string)row["output_file"]; |
|
You can of course use XmlReader, XmlDocument etc to create and maintain more complex ini files. But this is a quick way to maintain a simple property set. |
本文介绍了一种使用XML文件及DataSet来替代传统Ini文件的方法,适用于需要简单配置的应用场景。通过这种方式可以更方便地维护配置参数。
1469

被折叠的 条评论
为什么被折叠?



