Skip to content

Commit 4eb0f38

Browse files
author
LoneWandererProductions
committed
some smaller touchups
1 parent c64849e commit 4eb0f38

1 file changed

Lines changed: 46 additions & 7 deletions

File tree

ExtendedSystemObjects/CategorizedDictionary.cs

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,7 @@ public void Add(string category, TK key, TV value)
145145
_lock.EnterWriteLock();
146146
try
147147
{
148-
if (_data.ContainsKey(key))
149-
{
150-
throw new ArgumentException($"{ExtendedSystemObjectsResources.ErrorKeyExists}{key}");
151-
}
152-
153-
_data[key] = (category, value);
148+
AddInternal(category, key, value);
154149
}
155150
finally
156151
{
@@ -164,11 +159,21 @@ public void Add(string category, TK key, TV value)
164159
/// <param name="key">The key.</param>
165160
/// <param name="value">The value.</param>
166161
public void Add(TK key, TV value)
162+
{
163+
Add(string.Empty, key, value);
164+
}
165+
166+
/// <summary>
167+
/// Removes the specified key.
168+
/// </summary>
169+
/// <param name="key">The key.</param>
170+
/// <returns>If item was removed</returns>
171+
public bool Remove(TK key)
167172
{
168173
_lock.EnterWriteLock();
169174
try
170175
{
171-
Add(string.Empty, key, value);
176+
return _data.Remove(key);
172177
}
173178
finally
174179
{
@@ -345,6 +350,22 @@ public List<KeyValuePair<TK, TV>> ToKeyValueList()
345350
}
346351
}
347352

353+
/// <summary>
354+
/// Clears this instance.
355+
/// </summary>
356+
public void Clear()
357+
{
358+
_lock.EnterWriteLock();
359+
try
360+
{
361+
_data.Clear();
362+
}
363+
finally
364+
{
365+
_lock.ExitWriteLock();
366+
}
367+
}
368+
348369
/// <summary>
349370
/// Checks if two CategorizedDictionary instances are equal and provides a message.
350371
/// </summary>
@@ -449,5 +470,23 @@ public override int GetHashCode()
449470
return hashCode;
450471
}
451472
}
473+
474+
/// <summary>
475+
/// Adds the internal.
476+
/// </summary>
477+
/// <param name="category">The category.</param>
478+
/// <param name="key">The key.</param>
479+
/// <param name="value">The value.</param>
480+
/// <exception cref="System.ArgumentException"></exception>
481+
private void AddInternal(string category, TK key, TV value)
482+
{
483+
if (_data.ContainsKey(key))
484+
{
485+
throw new ArgumentException($"{ExtendedSystemObjectsResources.ErrorKeyExists}{key}");
486+
}
487+
488+
_data[key] = (category, value);
489+
}
490+
452491
}
453492
}

0 commit comments

Comments
 (0)