Skip to content

Commit bc3b0c9

Browse files
authored
Update INIConfigIO.md
1 parent 2eca189 commit bc3b0c9

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/usage/INIConfigIO.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# INIConfigIO
2+
3+
DDS.Net.Connector.Helpers.**INIConfigIO** provides an easy to use interface for reading and writing INI files. Its constructor simply takes the INI file name and an optional implementation of [ILogger](./ILogger.md) interface:
4+
5+
```csharp
6+
INIConfigIO(string filename, ILogger? logger = null)
7+
```
8+
9+
It can be simply instantiated:
10+
11+
```csharp
12+
INIConfigIO iniFile = new INIConfigIO("file.ini");
13+
```
14+
15+
16+
Its instance functions help in reading and writing the INI file, they include:
17+
18+
* Clear() - Clears the in-memory data but does not effect the file till it is saved.
19+
* SaveFile() - Saves the in-memory data into the given file.
20+
21+
* IEnumerable<string> GetSectionNames() - Gets all the section names present in the file.
22+
* string GetString(string key, string defaultValue = "") - Gets a value as a string, default value is returned when the key is not present in the file.
23+
* int GetInteger(string key, int defaultValue = -1) - Gets a value as an integer, default value is returned when the key is not present in the file.
24+
* float GetFloat(string key, float defaultValue = 0) - Gets a value as a float, default value is returned when the key is not present in the file.
25+
* double GetDouble(string key, double defaultValue = 0) - Gets a value as a double, default value is returned when the key is not present in the file.
26+
27+
* SetString(string key, string value) - Sets specified key's value to the given value
28+
* SetInteger(string key, int value) - Sets specified key's value to the given value
29+
* SetFloat(string key, float value) - Sets specified key's value to the given value
30+
* SetDouble(string key, double value) - Sets specified key's value to the given value
31+
32+
33+
For example, consider the following file:
34+
35+
```ini
36+
[A]
37+
a = 5
38+
b = 6
39+
40+
[B]
41+
a = 10
42+
b = 20
43+
```
44+
45+
46+
Its values can be read as:
47+
48+
```csharp
49+
INIConfigIO iniFile = new INIConfigIO("file.ini");
50+
51+
string value1 = iniFile.GetString("A/a"); // "5"
52+
string value2 = iniFile.GetString("A/b"); // "6"
53+
54+
int value3 = iniFile.GetInteger("B/a"); // 10
55+
int value4 = iniFile.GetInteger("B/b"); // 20
56+
```
57+
58+
59+

0 commit comments

Comments
 (0)