7.8 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T04:27:33.942396+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | d5502ead5db3d623 |
SettingsCollection<TKey, TItem> Module Documentation
1. Purpose
The SettingsCollection<TKey, TItem> class provides a dictionary-based collection that notifies subscribers of changes (add, remove, modify, clear) via the CollectionItemPropertyChanged event. It extends IDictionary<TKey, TItem> to offer standard dictionary operations while adding reactive behavior for UI binding or state synchronization scenarios. This module exists to decouple state mutation from side-effect logic (e.g., persistence, UI updates) by enabling consumers to subscribe to change events rather than manually tracking mutations.
2. Public Interface
SettingsCollection<TKey, TItem> : IDictionary<TKey, TItem>
Event
CollectionItemPropertyChanged
event EventHandler<SettingsChangedEventArgs<TKey, TItem>>
Fired whenever an item is added, removed, modified, or the collection is cleared.
Properties (from IDictionary<TKey, TItem>)
-
this[TKey key]
TItem this[TKey key] { get; set; }
Gets or sets the value for the specifiedkey. Setting a value fires aModifiedevent (note: incorrectly firesAddper implementation—see Gotchas). -
Keys
ICollection<TKey> Keys { get; }
Returns the collection of keys. -
Values
ICollection<TItem> Values { get; }
Returns the collection of values. -
Count
int Count { get; }
Returns the number of key-value pairs. -
IsReadOnly
bool IsReadOnly { get; }
Alwaysfalse.
Methods (from IDictionary<TKey, TItem>)
-
Add(TKey key, TItem value)
Adds a key-value pair. FiresCollectionItemPropertyChangedwithChangeSettingType.Add. -
Add(KeyValuePair<TKey, TItem> item)
Adds a key-value pair. FiresCollectionItemPropertyChangedwithChangeSettingType.Add. -
Remove(TKey key)
Removes the entry with the specifiedkey. Returnstrueif removed. FiresCollectionItemPropertyChangedwithChangeSettingType.Remove. -
Remove(KeyValuePair<TKey, TItem> item)
Removes the entry matching the key ofitem. Returnstrueif removed. FiresCollectionItemPropertyChangedwithChangeSettingType.Remove. -
Clear()
Removes all entries. FiresCollectionItemPropertyChangedwithChangeSettingType.ClearAll. -
ContainsKey(TKey key)
bool ContainsKey(TKey key)
Returnstrueifkeyexists. -
Contains(KeyValuePair<TKey, TItem> item)
bool Contains(KeyValuePair<TKey, TItem> item)
Returnstrueif both key and value exist in the collection. -
TryGetValue(TKey key, out TItem value)
bool TryGetValue(TKey key, out TItem value)
Returnstrueand setsvalueifkeyexists. -
CopyTo(KeyValuePair<TKey, TItem>[] array, int arrayIndex)
ThrowsNotImplementedException. -
GetEnumerator()
IEnumerator<KeyValuePair<TKey, TItem>> GetEnumerator()
Returns an enumerator over the collection. -
IEnumerable.GetEnumerator()
Explicit implementation ofIEnumerable.GetEnumerator().
SettingsChangedEventArgs<TKey, TItem> : EventArgs
Constructors
-
SettingsChangedEventArgs(ChangeSettingType changeType)
Initializes with only theChangeType. -
SettingsChangedEventArgs(ChangeSettingType changeType, TKey key)
Initializes withChangeTypeandKey. -
SettingsChangedEventArgs(ChangeSettingType changeType, TKey key, TItem item)
Initializes withChangeType,Key, andItem.
Properties
-
ChangeType
ChangeSettingType ChangeType { get; }
Type of change (Add,Remove,Modified, orClearAll). -
Key
TKey Key { get; }
Key associated with the change (may be default ifClearAll). -
Item
TItem Item { get; }
Value associated with the change (may be default ifRemoveorClearAll).
ChangeSettingType Enum
-
Add = 0
A new item was added. -
Remove = 1
An item was removed. -
Modified = 3
An existing item’s value was updated. -
ClearAll = 4
The entire collection was cleared.
3. Invariants
-
Event Firing:
Add,Remove, andClearAllalways fire an event.this[key] = valuealways fires an event (withChangeType.Add, per implementation—see Gotchas).- Events are fired after the underlying dictionary is mutated (i.e., state is consistent at event time).
-
Event Arguments:
- For
Add/Modified:KeyandItemare non-null/non-default (assumingTKey/TItemallow it);ChangeTypeisAdd. - For
Remove:Itemis default (default(TItem));ChangeTypeisRemove. - For
ClearAll:KeyandItemare default;ChangeTypeisClearAll.
- For
-
No Partial Updates:
Only full additions, removals, or clears trigger events—no partial or batched updates.
4. Dependencies
Dependencies of this module:
System.Collections.Generic
ProvidesDictionary<TKey, TItem>,ICollection<TKey>,ICollection<TItem>,IEnumerator<T>,IDictionary<TKey, TItem>.System
ProvidesEventArgs,EventHandler<T>,NotImplementedException,enum.
Dependencies on this module:
DataPRO.Core.Settingsnamespace
Used internally by consumers (e.g.,SettingsChangedEventArgsandChangeSettingTypeare public and likely used elsewhere in the codebase to handle settings changes).
Inferred Usage:
- Likely consumed by UI layers or configuration managers that need to react to settings changes (e.g., saving to disk, updating UI controls).
5. Gotchas
-
Incorrect
ModifiedEvent Type:
The indexer setter (this[TKey key] { set { ... } }) firesChangeSettingType.Addinstead ofChangeSettingType.Modified. This is inconsistent with the semantic meaning of "modify" and may mislead consumers expectingModifiedfor updates.
Example:collection["foo"] = "bar"; // Fires Add, not Modified -
CopyToNot Implemented:
CopyTo(KeyValuePair<TKey, TItem>[], int)throwsNotImplementedException. This violates theICollection<KeyValuePair<TKey, TItem>>contract and may cause runtime failures if used (e.g., via LINQ’sToArray()orToList()). -
Contains(KeyValuePair<TKey, TItem>)Semantics:
Checks both key and value equality. This is stricter than typical dictionaryContainsbehavior (which usually checks only key), and may cause confusion. -
No Validation on Keys/Values:
No checks fornullkeys (ifTKeyis a reference type) or duplicate keys—relies on underlyingDictionary<TKey, TItem>to throwArgumentNullException/ArgumentException. -
No Thread Safety:
No synchronization primitives are used. Concurrent access may corrupt state or cause race conditions in event firing. -
Event Subscribers May Receive Unexpected
ItemValues:
ForRemoveandClearAll,Itemisdefault(TItem). Consumers must not assumeItemis always meaningful. -
No
ModifiedEvent for Direct Assignment:
Since the indexer usesAddsemantics, there is no way to distinguish between adding a new key and updating an existing key via the event—unless the consumer tracks state themselves. -
Historical Quirk:
TheClearAllevent omitsKeyandItem(bothdefault), while other operations populate them. This is consistent with the enum design but may require special handling in event handlers.
Documentation generated from source files only. No external behavior or assumptions beyond the provided code.