[]
Represents an OwnedCollection<TItem> of uniquely elements, each element should have unique key.
public abstract class OwnedKeyedCollection<TKey, TItem> : OwnedCollection<TItem>, IList<TItem>, ICollection<TItem>, IReadOnlyList<TItem>, IReadOnlyCollection<TItem>, IEnumerable<TItem>, IOwnedObject, IList, ICollection, IEnumerable where TItem : IOwnedObject
TKey
The type of keys in the collection.
TItem
The type of items in the collection.
protected OwnedKeyedCollection()
Throws an exception if collection already contains item with specified key.
public virtual void CheckKey(TItem item, TKey oldKey, TKey newKey)
item
TItemThe item to check.
oldKey
TKeyThe old key.
newKey
TKeyThe new key.
protected override void ClearItems()
When implemented in a derived class, extracts the key from the specified element.
protected abstract TKey GetKeyForItem(TItem item)
item
TItemThe element from which to extract the key.
The key for the specified element.
Returns the 0-based index of a TItem
with specified key in the current OwnedKeyedCollection<TKey, TItem>.
public int IndexOfKey(TKey key)
key
TKeyThe key of the item to locate.
The 0-based index of the specified item, or -1 if the item was not found.
protected override void InsertItem(int index, TItem item)
index
intitem
TItemprotected override void RemoveItem(int index)
index
intprotected override void SetItem(int index, TItem item)
index
intitem
TItemGet an item with specified key.
public bool TryGetValue(TKey key, out TItem item)
key
TKeyThe key of the item.
item
TItemThe item or default value if not found.
true if item was found, false otherwise.