-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIIniSection.cs
162 lines (143 loc) · 7.67 KB
/
IIniSection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Collections.Generic;
namespace Rampastring.Tools
{
public interface IIniSection
{
/// <summary>
/// Returns the name of the INI section.
/// </summary>
string SectionName { get; }
/// <summary>
/// Adds a key to the INI section.
/// Throws a <see cref="InvalidOperationException"/> if the key already exists.
/// Use <see cref="AddOrReplaceKey(string, string)"/> if you want to replace
/// an existing key instead.
/// </summary>
/// <param name="keyName">The name of the INI key.</param>
/// <param name="value">The value of the INI key.</param>
void AddKey(string keyName, string value);
/// <summary>
/// Adds a key to the INI section, or replaces the key's value if the key
/// already exists.
/// </summary>
/// <param name="keyName">The name of the INI key.</param>
/// <param name="value">The value of the INI key.</param>
void AddOrReplaceKey(string keyName, string value);
/// <summary>
/// Removes a key from the INI section.
/// Does not throw an exception if the key does not exist.
/// </summary>
/// <param name="keyName">The name of the INI key to remove.</param>
void RemoveKey(string keyName);
/// <summary>
/// Returns a boolean value from the INI section.
/// </summary>
/// <param name="key">The name of the INI key.</param>
/// <param name="defaultValue">The value to return if the section or key wasn't found,
/// or converting the key's value to a boolean failed.</param>
/// <returns>The given key's value if the section and key was found and
/// the value is a valid boolean. Otherwise the given defaultValue.</returns>
bool GetBooleanValue(string key, bool defaultValue);
/// <summary>
/// Returns a double-precision floating point value from the INI section.
/// </summary>
/// <param name="key">The name of the INI key.</param>
/// <param name="defaultValue">The value to return if the section or key wasn't found,
/// or converting the key's value to a double failed.</param>
/// <returns>The given key's value if the section and key was found and
/// the value is a valid double. Otherwise the given defaultValue.</returns>
double GetDoubleValue(string key, double defaultValue);
/// <summary>
/// Returns an integer value from the INI section.
/// </summary>
/// <param name="key">The name of the INI key.</param>
/// <param name="defaultValue">The value to return if the section or key wasn't found,
/// or converting the key's value to an integer failed.</param>
/// <returns>The given key's value if the section and key was found and
/// the value is a valid integer. Otherwise the given defaultValue.</returns>
int GetIntValue(string key, int defaultValue);
/// <summary>
/// Parses and returns a list value of a key in the INI section.
/// </summary>
/// <typeparam name="T">The type of the list elements.</typeparam>
/// <param name="key">The INI key.</param>
/// <param name="separator">The separator between the list elements.</param>
/// <param name="converter">The function that converts the list elements from strings to the given type.</param>
/// <returns>A list that contains the parsed elements.</returns>
List<T> GetListValue<T>(string key, char separator, Func<string, T> converter);
/// <summary>
/// Returns a single-precision floating point value from the INI section.
/// </summary>
/// <param name="key">The name of the INI key.</param>
/// <param name="defaultValue">The value to return if the section or key wasn't found,
/// or converting the key's value to a float failed.</param>
/// <returns>The given key's value if the section and key was found and
/// the value is a valid float. Otherwise the given defaultValue.</returns>
float GetSingleValue(string key, float defaultValue);
/// <summary>
/// Returns a string value from the INI section.
/// </summary>
/// <param name="key">The name of the INI key.</param>
/// <param name="defaultValue">The value to return if the section or key wasn't found.</param>
/// <returns>The given key's value if the section and key was found. Otherwise the given defaultValue.</returns>
string GetStringValue(string key, string defaultValue);
/// <summary>
/// Checks if the specified INI key exists in this section.
/// </summary>
/// <param name="key">The INI key.</param>
/// <returns>True if the key exists in this section, otherwise false.</returns>
bool KeyExists(string key);
/// <summary>
/// Sets the boolean value of a key in the INI section.
/// If the key doesn't exist, it is created.
/// </summary>
/// <param name="key">The name of the INI key.</param>
/// <param name="value">The value of the INI key.</param>
void SetBooleanValue(string key, bool value);
/// <summary>
/// Sets the double-precision floating point value of a key in the INI section.
/// If the key doesn't exist, it is created.
/// </summary>
/// <param name="key">The name of the INI key.</param>
/// <param name="value">The value of the INI key.</param>
void SetDoubleValue(string key, double value);
/// <summary>
/// Sets the single-precision floating point value of a key in the INI section.
/// If the key doesn't exist, it is created.
/// </summary>
/// <param name="key">The name of the INI key.</param>
/// <param name="value">The value of the INI key.</param>
void SetFloatValue(string key, float value);
/// <summary>
/// Sets the integer value of a key in the INI section.
/// If the key doesn't exist, it is created.
/// </summary>
/// <param name="key">The name of the INI key.</param>
/// <param name="value">The value of the INI key.</param>
void SetIntValue(string key, int value);
/// <summary>
/// Sets the list value of a key in the INI section.
/// The list elements are converted to strings using the list element's
/// ToString method and the given separator is applied between the elements.
/// </summary>
/// <typeparam name="T">The type of the list elements.</typeparam>
/// <param name="key">The INI key.</param>
/// <param name="list">The list.</param>
/// <param name="separator">The separator between list elements.</param>
void SetListValue<T>(string key, List<T> list, char separator);
/// <summary>
/// Sets the string value of a key in the INI section.
/// If the key doesn't exist, it is created.
/// </summary>
/// <param name="key">The name of the INI key.</param>
/// <param name="value">The value of the INI key.</param>
void SetStringValue(string key, string value);
/// <summary>
/// Parses and returns a path string from the INI section.
/// The path string has all of its directory separators ( / \ )
/// replaced with an environment-specific one.
/// </summary>
string GetPathStringValue(string key, string defaultValue);
}
}