@@ -81,7 +81,13 @@ public bool KeyExists(string key)
81
81
return Settings . Values . ContainsKey ( key ) ;
82
82
}
83
83
84
- /// <inheritdoc />
84
+ /// <summary>
85
+ /// Retrieves a single item by its key.
86
+ /// </summary>
87
+ /// <typeparam name="T">Type of object retrieved.</typeparam>
88
+ /// <param name="key">Key of the object.</param>
89
+ /// <param name="default">Default value of the object.</param>
90
+ /// <returns>The TValue object</returns>
85
91
public T Read < T > ( string key , T @default = default )
86
92
{
87
93
if ( ! Settings . Values . TryGetValue ( key , out var valueObj ) || valueObj == null )
@@ -92,6 +98,17 @@ public T Read<T>(string key, T @default = default)
92
98
return Serializer . Deserialize < T > ( valueObj as string ) ;
93
99
}
94
100
101
+ /// <inheritdoc />
102
+ public T Read < T > ( string key )
103
+ {
104
+ if ( Settings . Values . TryGetValue ( key , out var valueObj ) && valueObj != null )
105
+ {
106
+ return Serializer . Deserialize < T > ( valueObj as string ) ;
107
+ }
108
+
109
+ throw new KeyNotFoundException ( key ) ;
110
+ }
111
+
95
112
/// <inheritdoc />
96
113
public void Save < T > ( string key , T value )
97
114
{
@@ -101,7 +118,11 @@ public void Save<T>(string key, T value)
101
118
/// <inheritdoc />
102
119
public void Delete ( string key )
103
120
{
104
- Settings . Values . Remove ( key ) ;
121
+ var removed = Settings . Values . Remove ( key ) ;
122
+ if ( ! removed )
123
+ {
124
+ throw new KeyNotFoundException ( key ) ;
125
+ }
105
126
}
106
127
107
128
/// <inheritdoc />
@@ -196,12 +217,19 @@ public void Save<T>(string compositeKey, IDictionary<string, T> values)
196
217
/// </summary>
197
218
/// <param name="compositeKey">Key of the composite (that contains settings).</param>
198
219
/// <param name="key">Key of the object.</param>
220
+ /// <exception cref="KeyNotFoundException">Throws when the specified composite/settings key is not found.</exception>
199
221
public void Delete ( string compositeKey , string key )
200
222
{
201
- if ( KeyExists ( compositeKey ) )
223
+ if ( ! KeyExists ( compositeKey ) )
202
224
{
203
- ApplicationDataCompositeValue composite = ( ApplicationDataCompositeValue ) Settings . Values [ compositeKey ] ;
204
- composite . Remove ( key ) ;
225
+ throw new KeyNotFoundException ( $ "Composite key not found: { compositeKey } ") ;
226
+ }
227
+
228
+ ApplicationDataCompositeValue composite = ( ApplicationDataCompositeValue ) Settings . Values [ compositeKey ] ;
229
+
230
+ if ( ! composite . Remove ( key ) )
231
+ {
232
+ throw new KeyNotFoundException ( $ "Settings key not found: { key } ") ;
205
233
}
206
234
}
207
235
0 commit comments