Class NamedCollection<T>
- Namespace
- NanoByte.Common.Collections
- Assembly
- NanoByte.Common.dll
A keyed collection (pseudo-dictionary) of INamed objects. Case-insensitive!
public class NamedCollection<T> : KeyedCollection<string, T>, ICloneable<NamedCollection<T>> where T : INamed
Type Parameters
T
- Inheritance
-
objectCollection<T>KeyedCollection<string, T>NamedCollection<T>
- Implements
- Extension Methods
Remarks
Elements are automatically maintained in an alphabetically sorted order. Suitable for XML serialization.
Constructors
NamedCollection()
A keyed collection (pseudo-dictionary) of INamed objects. Case-insensitive!
public NamedCollection()
Remarks
Elements are automatically maintained in an alphabetically sorted order. Suitable for XML serialization.
NamedCollection(IEnumerable<T>)
Creates a new named collection pre-filled with elements.
public NamedCollection(IEnumerable<T> elements)
Parameters
elementsIEnumerable<T>The elements to pre-fill the collection with. Must all have unique Names!
Methods
ClearItems()
Removes all elements from the System.Collections.ObjectModel.KeyedCollection<TKey, TItem>.
protected override void ClearItems()
Clone()
Creates a shallow copy of this collection (elements are not cloned).
public virtual NamedCollection<T> Clone()
Returns
- NamedCollection<T>
The cloned collection.
GetKeyForItem(T)
When implemented in a derived class, extracts the key from the specified element.
protected override string GetKeyForItem(T item)
Parameters
itemTThe element from which to extract the key.
Returns
- string
The key for the specified element.
InsertItem(int, T)
Inserts an element into the System.Collections.ObjectModel.KeyedCollection<TKey, TItem> at the specified index.
protected override void InsertItem(int index, T item)
Parameters
indexintThe zero-based index at which
itemshould be inserted.itemTThe object to insert.
Exceptions
- ArgumentOutOfRangeException
indexis less than 0.-or-indexis greater than System.Collections.ObjectModel.Collection<T>.Count.
RemoveItem(int)
Removes the element at the specified index of the System.Collections.ObjectModel.KeyedCollection<TKey, TItem>.
protected override void RemoveItem(int index)
Parameters
indexintThe index of the element to remove.
Rename(T, string)
Renames an element in the list. Renaming an element in the list directly (without using this method) will prevent lookups from working properly!
[CollectionAccess(CollectionAccessType.ModifyExistingContent)]
public void Rename(T element, string newName)
Parameters
elementTThe element to rename.
newNamestringThe new Name for the element.
Exceptions
- KeyNotFoundException
The
elementis not in the collection.- InvalidOperationException
The
newNameis already taken by another element in the collection.
SetItem(int, T)
Replaces the item at the specified index with the specified item.
protected override void SetItem(int index, T item)
Parameters
indexintThe zero-based index of the item to be replaced.
itemTThe new item.
Events
CollectionChanged
public event Action<object>? CollectionChanged
Event Type
- Action<object>