-
Notifications
You must be signed in to change notification settings - Fork 4
/
Interfaces.cs
179 lines (148 loc) · 5.65 KB
/
Interfaces.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
namespace Menees
{
#region Using Directives
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
#endregion
#region public ISettingsNode
/// <summary>
/// Provides a generic interface for a single node in an <see cref="ISettingsStore"/>.
/// </summary>
public interface ISettingsNode
{
#region Public Properties
/// <summary>
/// Gets the name of the current node.
/// </summary>
string NodeName { get; }
/// <summary>
/// Gets the number of settings in the current node.
/// </summary>
int SettingCount { get; }
/// <summary>
/// Gets the number of sub-nodes of the current node.
/// </summary>
int SubNodeCount { get; }
/// <summary>
/// Gets the parent settings node.
/// </summary>
ISettingsNode? ParentNode { get; }
#endregion
#region Public Methods
/// <summary>
/// Gets a setting's value as a string.
/// </summary>
/// <param name="settingName">The name of a setting.</param>
/// <param name="defaultValue">The default value to return if the setting isn't found.</param>
/// <returns>The setting's current value or the default value.</returns>
string GetValue(string settingName, string defaultValue);
/// <summary>
/// Gets a setting's value as a string.
/// </summary>
/// <param name="settingName">The name of a setting.</param>
/// <param name="defaultValue">The default value to return if the setting isn't found.</param>
/// <returns>The setting's current value or the default value.</returns>
string? GetValueN(string settingName, string? defaultValue);
/// <summary>
/// Sets a setting's value as a string.
/// </summary>
/// <param name="settingName">The name of a new or existing setting.</param>
/// <param name="value">The new value for the setting.</param>
void SetValue(string settingName, string? value);
/// <summary>
/// Gets a setting's value as an Int32.
/// </summary>
/// <param name="settingName">The name of a setting.</param>
/// <param name="defaultValue">The default value to return if the setting isn't found.</param>
/// <returns>The setting's current value or the default value.</returns>
int GetValue(string settingName, int defaultValue);
/// <summary>
/// Sets a setting's value as a Int32.
/// </summary>
/// <param name="settingName">The name of a new or existing setting.</param>
/// <param name="value">The new value for the setting.</param>
void SetValue(string settingName, int value);
/// <summary>
/// Gets a setting's value as a boolean.
/// </summary>
/// <param name="settingName">The name of a setting.</param>
/// <param name="defaultValue">The default value to return if the setting isn't found.</param>
/// <returns>The setting's current value or the default value.</returns>
bool GetValue(string settingName, bool defaultValue);
/// <summary>
/// Sets a setting's value as a Boolean.
/// </summary>
/// <param name="settingName">The name of a new or existing setting.</param>
/// <param name="value">The new value for the setting.</param>
void SetValue(string settingName, bool value);
/// <summary>
/// Gets a setting's value as an enum.
/// </summary>
/// <param name="settingName">The name of a setting.</param>
/// <param name="defaultValue">The default value to return if the setting isn't found.</param>
/// <returns>The setting's current value or the default value.</returns>
T GetValue<T>(string settingName, T defaultValue)
where T : struct;
/// <summary>
/// Sets a setting's value as an enum.
/// </summary>
/// <param name="settingName">The name of a new or existing setting.</param>
/// <param name="value">The new value for the setting.</param>
void SetValue<T>(string settingName, T value)
where T : struct;
/// <summary>
/// Gets the names of all the settings in the current node.
/// </summary>
/// <returns>A collection of setting names.</returns>
IList<string> GetSettingNames();
/// <summary>
/// Deletes a setting from the current node.
/// </summary>
/// <param name="settingName">The name of a setting.</param>
void DeleteSetting(string settingName);
/// <summary>
/// Gets the names of all the sub-nodes of the current node.
/// </summary>
/// <returns>A collection of node names.</returns>
IList<string> GetSubNodeNames();
/// <summary>
/// Recursively deletes the sub-node with the specified name.
/// </summary>
/// <param name="nodeNameOrPath">The name or '\'-separated path of a sub-node.</param>
void DeleteSubNode(string nodeNameOrPath);
/// <summary>
/// Gets an existing sub-node or creates a new sub-node with the specified name.
/// </summary>
/// <param name="nodeNameOrPath">The name or '\'-separated path of a sub-node.</param>
/// <returns>An existing node if one is found or a new node if necessary.</returns>
ISettingsNode GetSubNode(string nodeNameOrPath);
/// <summary>
/// Gets a sub-node if it already exists.
/// </summary>
/// <param name="nodeNameOrPath">The name or '\'-separated path of a sub-node.</param>
/// <returns>An existing node if one is found, or null otherwise.</returns>
ISettingsNode? TryGetSubNode(string nodeNameOrPath);
#endregion
}
#endregion
#region public ISettingsStore
/// <summary>
/// Provides a generic interface for working with a hierarchy of <see cref="ISettingsNode"/>s.
/// </summary>
public interface ISettingsStore : IDisposable
{
/// <summary>
/// Gets the root node in the store.
/// </summary>
ISettingsNode RootNode { get; }
/// <summary>
/// Saves any changes that have been made to settings and nodes.
/// </summary>
void Save();
}
#endregion
}