KeyedCollection

Ecng.Collections

Represents an abstract dictionary-backed collection that manages key-value pairs with customizable behavior.

実装: IDictionary<T, T>, ICollection<KeyValuePair<T, T>>, IEnumerable<KeyValuePair<T, T>>, IEnumerable

コンストラクター

KeyedCollection
protected KeyedCollection(IDictionary<TKey, TValue> innerDictionary)
keyedCollection = KeyedCollection(innerDictionary)

Represents an abstract dictionary-backed collection that manages key-value pairs with customizable behavior.

KeyedCollection
protected KeyedCollection(IEqualityComparer<TKey> comparer)
keyedCollection = KeyedCollection(comparer)

Initializes a new instance of the KeyedCollection class with a specified key comparer.

comparer
The equality comparer for keys, or null to use the default comparer.
KeyedCollection
protected KeyedCollection()
keyedCollection = KeyedCollection()

Initializes a new instance of the KeyedCollection class with a default dictionary.

プロパティ

Count
public virtual int Count { get; }
value = keyedCollection.Count

Gets the number of key-value pairs in the collection.

InnerDictionary
protected IDictionary<TKey, TValue> InnerDictionary { get; }
value = keyedCollection.InnerDictionary

Gets the underlying dictionary that stores the key-value pairs.

Item
public virtual TValue Item { get; set; }
value = keyedCollection.Item
keyedCollection.Item = value

Gets or sets the value associated with the specified key.

key
The key whose value is to be retrieved or set.

戻り値: The value associated with the specified key.

Keys
public ICollection<TKey> Keys { get; }
value = keyedCollection.Keys

Gets a collection containing the keys in the dictionary.

Values
public ICollection<TValue> Values { get; }
value = keyedCollection.Values

Gets a collection containing the values in the dictionary.

メソッド

Add
public void Add(KeyValuePair<TKey, TValue> item)
keyedCollection.Add(item)

Adds a key-value pair to the collection.

item
The key-value pair to add.
Add
public virtual void Add(TKey key, TValue value)
keyedCollection.Add(key, value)

Adds the specified key-value pair to the collection.

key
The key to add.
value
The value to add.
CanAdd
protected virtual bool CanAdd(TKey key, TValue value)
result = keyedCollection.CanAdd(key, value)

Determines whether a key-value pair can be added to the collection.

key
The key to check.
value
The value to check.

戻り値: True if the pair can be added; otherwise, false.

Clear
public virtual void Clear()
keyedCollection.Clear()

Removes all items from the collection.

Contains
public bool Contains(KeyValuePair<TKey, TValue> item)
result = keyedCollection.Contains(item)

Determines whether the collection contains a specific key-value pair.

item
The key-value pair to locate.

戻り値: True if the pair is found; otherwise, false.

ContainsKey
public bool ContainsKey(TKey key)
result = keyedCollection.ContainsKey(key)

Determines whether the collection contains an element with the specified key.

key
The key to locate.

戻り値: True if the key is found; otherwise, false.

CopyTo
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
keyedCollection.CopyTo(array, arrayIndex)

Copies the elements of the collection to an array, starting at the specified index.

array
The destination array to copy to.
arrayIndex
The zero-based index in the array at which copying begins.
GetEnumerator
public virtual IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
result = keyedCollection.GetEnumerator()

Returns an enumerator that iterates through the collection.

戻り値: An IEnumerator that can be used to iterate through the collection.

OnAdded
protected virtual void OnAdded(TKey key, TValue value)
keyedCollection.OnAdded(key, value)

Called after a key-value pair has been added to the collection.

key
The key that was added.
value
The value that was added.
OnAdding
protected virtual void OnAdding(TKey key, TValue value)
keyedCollection.OnAdding(key, value)

Called before adding a key-value pair to the collection.

key
The key being added.
value
The value being added.
OnCleared
protected virtual void OnCleared()
keyedCollection.OnCleared()

Called after all items have been cleared from the collection.

OnClearing
protected virtual void OnClearing()
keyedCollection.OnClearing()

Called before clearing all items from the collection.

OnRemoved
protected virtual void OnRemoved(TKey key, TValue value)
keyedCollection.OnRemoved(key, value)

Called after a key-value pair has been removed from the collection.

key
The key that was removed.
value
The value that was removed.
OnRemoving
protected virtual void OnRemoving(TKey key, TValue value)
keyedCollection.OnRemoving(key, value)

Called before removing a key-value pair from the collection.

key
The key being removed.
value
The value being removed.
OnSetted
protected virtual void OnSetted(TKey key, TValue value)
keyedCollection.OnSetted(key, value)

Called after a new value has been set for an existing key.

key
The key that was updated.
value
The new value that was set.
OnSetting
protected virtual void OnSetting(TKey key, TValue value)
keyedCollection.OnSetting(key, value)

Called before setting a new value for an existing key.

key
The key being updated.
value
The new value to set.
Remove
public bool Remove(KeyValuePair<TKey, TValue> item)
result = keyedCollection.Remove(item)

Removes a specific key-value pair from the collection.

item
The key-value pair to remove.

戻り値: True if the pair was found and removed; otherwise, false.

Remove
public virtual bool Remove(TKey key)
result = keyedCollection.Remove(key)

Removes the value with the specified key from the collection.

key
The key of the element to remove.

戻り値: True if the element was found and removed; otherwise, false.

System#Collections#IEnumerable#GetEnumerator()

Returns an enumerator that iterates through the collection (non-generic version).

戻り値: An IEnumerator that can be used to iterate through the collection.

TryGetValue
public virtual bool TryGetValue(TKey key, TValue value)
result = keyedCollection.TryGetValue(key, value)

Attempts to retrieve the value associated with the specified key.

key
The key to locate.
value
When this method returns, contains the value associated with the key if found; otherwise, the default value of .

戻り値: True if the key was found; otherwise, false.